[Angular] Freshness Caching Policy - Network First, Cache Last

In some cases, you want to get fresh data instead of cache data to the screen, such as stock applications.

Only fallback to cache data if cannot get response from API, we can aslo add timeout for example 10s. 

{
  "index": "/index.html",
  "assetGroups": [{
    "name": "app",
    "installMode": "prefetch",
    "resources": {
      "files": [
        "/favicon.ico",
        "/index.html"
      ],
      "versionedFiles": [
        "/*.bundle.css",
        "/*.bundle.js",
        "/*.chunk.js"
      ]
    }
  }, {
    "name": "assets",
    "installMode": "lazy",
    "updateMode": "prefetch",
    "resources": {
      "files": [
        "/assets/**"
      ]
    }
  }],
  "dataGroups": [
    {
      "name": "lessons-api",
      "urls": [
        "/api/lessons"
      ],
      "cacheConfig": {
        "strategy": "freshness",
        "timeout":"10s",
        "maxAge": "1d",
        "maxSize": 100
      }
    }
  ]
}

 

posted @ 2018-04-19 01:56  Zhentiw  阅读(200)  评论(0编辑  收藏  举报