Manipulate cache in angular for PWA api calls

Discussão em 'Angular' iniciado por Mo3bius, Novembro 28, 2024.

  1. Mo3bius

    Mo3bius Guest

    I am trying to make a part of my angular app offline capable. The project has already the package @angular/pwa installed and the ngsw-config.json is succesfully caching api calls:

    {
    "$schema": "./node_modules/@angular/service-worker/config/schema.json",
    "index": "/index.html",
    ...

    "dataGroups": [
    {
    "name": "api-forms",
    "urls": [
    "/api/Books",
    "/api/Videos",
    ],
    "cacheConfig": {
    "strategy": "freshness",
    "maxSize": 100,
    "maxAge": "1d",
    "timeout": "10s"
    }
    }
    ]
    }


    My question now: How do I manipulate these cached api calls? For example, if a user is adding a book, the book cache should be updated. The only thing i found is using directly the CacheStorage api. This api works, but I need to specify exactly the name of the cache and api URL (no regex matching). Even worse, the cache name has some prefixes in it:

    Angular PWA and caching API

    What is the angular way here? Is this just not implemented yet? Am I doing something really strange and there is a better way?

    Continue reading...

Compartilhe esta Página