有角的服务工人。缓存接收到的数据

时间:2019-10-08 08:38:58

标签: angular service-worker

我想缓存接收到的JSON Web套接字。 接收数据时,我将其保存在对象中并希望对其进行缓存。 我在任何地方都找不到有关此信息。 我该怎么办?

我尝试指定url websocket,但是没有缓存。

{
  "$schema": "./node_modules/@angular/service-worker/config/schema.json",
  "index": "/index.html",
  "assetGroups": [
    {
      "name": "app",
      "installMode": "prefetch",
      "resources": {
        "files": [
          "/favicon.ico",
          "/index.html",
          "/manifest.webmanifest",
          "/*.css",
          "/*.js"
        ]
      }
    },
     {
      "name": "assets",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "resources": {
        "files": [
          "/assets/**",
          "/app/app.component.ts",
          "/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
        ]
      }
    }
  ],
    "dataGroups": [{
      "name": "api-freshness",
      "urls": ["wss://blablabla.ru/ws/"],
      "cacheConfig": {
        "strategy": "freshness",
        "maxSize": 100,
        "maxAge": "3d",
        "timeout": "5s"
      }
    }
  ]
}

1 个答案:

答案 0 :(得分:0)

我假设您通过发出命令 ng add @ angular / pwa 激活了PWA功能,并且上面的内容来自文件ngsw-config.json,该文件应放在src文件夹中。

尝试将通配符添加到数据组中url的值中,使其看起来像这样:

"urls": ["wss://blablabla.ru/ws/**"]