Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Combine fastest+maxAgeSeconds with offline support? #213

Open
ThaNarie opened this issue Jan 3, 2017 · 0 comments
Open

Combine fastest+maxAgeSeconds with offline support? #213

ThaNarie opened this issue Jan 3, 2017 · 0 comments

Comments

@ThaNarie
Copy link

ThaNarie commented Jan 3, 2017

I'm in a situation where I'm not sure if I have to write my own handler, or if there is a combination of settings that allow me to accomplish the following use case:

  1. I have requests that cannot be cached on cdn (because of user tokens), but for a single user I would like to cache that response for say an hour. In that time I would like to serve from the cache, but also hit the network to update in the background when new data came in.
    After an hour since the last request (let's say the next day), I always want to hit the network, because at that time the chance is higher that the response will be changed.

I think this can be accomplished by using fastest combined with maxAgeSeconds.

  1. I would like to have cached requests available for offline use later on.

Using maxAgeSeconds makes this impossible, since the cache entires will be removed.

When removing the maxAge, and still using 'fastest' for scenario 1, you end up being served an older entry and need a 'reload' before getting the new one.

custom handler

Thinking about this, when writing my own handler, I would probably want to introduce a new option (e.g. maxAgeSecondsFresh) and use that value as a condition for which strategy to use (and not delete the cache). When in that timeframe, use 'fastest', when outside that timeframe, use 'networkFirst'.
(And when no connectivity at all, cacheOnly should probably be chosen there).

This seems like a pretty common scenario. Maybe something that can be included in (a future version) of sw-toolbox? Any pointers are welcome as well!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant