1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How can i clear api's response cache after logout while using angular service worker?

Discussão em 'Angular' iniciado por mehranmb78, Novembro 8, 2024 às 06:53.

  1. mehranmb78

    mehranmb78 Guest

    I cache api's responses by using angular generated service worker , now i want to clear these caches after user decide to logout for this i made new custom service worker file which listens to messages from angular app and after that will try to clear the cache, but for checking when i put browser to offline mode and refresh the page i can still see that cached data, now i have question how can i clear them compeletly?

    Here is my custom servcie worker:

    importScripts('./ngsw-worker.js')
    self.addEventListener('message', async event => {
    const cacheNames = await self.caches.keys()
    for (let name of cacheNames) {
    await self.caches.delete(name)
    }
    console.log('All caches deleted.')
    })

    Continue reading...

Compartilhe esta Página