GoogleChromeLabs / sw-toolbox

[Deprecated] A collection of service worker tools for offlining runtime requests
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
3.61k stars 331 forks source link

cache lru #253

Closed publicocean0 closed 7 years ago

publicocean0 commented 7 years ago

it is possible to define a lru policy or a way last request is always cached end eventually delete the oldest? This will grant when cache works also when is full.

jeffposnick commented 7 years ago

Yes; for instance, using this example configuration from the docs:

toolbox.router.get(/\.ytimg\.com\//, toolbox.cacheFirst, {
  // Use a dedicated cache for the responses, separate from the default cache.
  cache: {
    name: 'youtube-thumbnails',
    // Store up to 10 entries in that cache.
    maxEntries: 10,
    // Expire any entries that are older than 30 seconds.
    maxAgeSeconds: 30
  }
});
publicocean0 commented 7 years ago

thanks it is very interesting. I explain my problem so you can understand better , maybe there is a solution here or maybe i can suggest a new feature here. I have a stream of contents arriving by websocket. I want implement a cache so browser dont ask the same contents. Initially i developped a cache using filesystem api ... it is cool but now fsapi are deprecated and anyway not implemented by all browsers. So I have a problem. Considering the cache limit in appcache is higher than indexdb (a lot ) .... i thought to use it. Content are arraybuffer. so if i save content as new Response() ... (maybe Response might permit also Stream of chunks) might work simulating a new fetch request. Image i want listen a mp3 file. When downloaded user play it ... but i cant keep always it (as a blob) in memory because is not a static page ... it is a stream of contents.... To use blob for handling media for me is a very bad solution ... but all browser use. Do you think using your library i can implement my idea?

jeffposnick commented 7 years ago

I don't think that's something that sw-toolbox will help with, no. I don't want to say that it's impossible using the Cache Storage API, but there's nothing in sw-toolbox that is relevant to that scenario.

publicocean0 commented 7 years ago

The problem there is nothing in html and web api rilevant for that scenario. i want suicide me :)