Cannot get Network first, then Cache strategy to work with Angular and Spring Boot

Discussão em 'Angular' iniciado por Dusto, Março 4, 2025.

  1. Dusto

    Dusto Guest

    I have made an angular PWA and tried implementing a Network first, then Cache strategy since I want to be support offline mode for some api resources.

    I have used Google Chrome to simulate no internet connection which works. But when adding a new entry into the db and then running the request when I am back online, it does not revalidate even tho I have specified it. It continues to serve the disk-cache state

    Spring:

    @Operation(description = UnitControllerDocs.GET_UNITS_METHOD_DESCRIPTION)
    @GetMapping
    public ResponseEntity<List<UnitDTO>> getUnits() {
    List<UnitDTO> units = unitFacade.getUnits();

    return ResponseEntity.ok()
    .header("Cache-Control", "public, max-age=31536000, must-revalidate")
    .body(units);
    }


    and in my nags-config.json:

    {
    "name": "select-items",
    "urls": [
    "/api/delivery-custom-fields",
    "/api/units",
    "/api/products"
    ],
    "cacheConfig": {
    "strategy": "freshness",
    "maxSize": 100,
    "maxAge": "365d",
    "timeout": "0u"
    }
    }

    Continue reading...

Compartilhe esta Página