mcollina / async-cache-dedupe

Async cache with dedupe support
MIT License
640 stars 40 forks source link

Implement stale while revalidate #45

Closed mcollina closed 1 year ago

mcollina commented 1 year ago

Signed-off-by: Matteo Collina hello@matteocollina.com

33

simone-sanfratello commented 1 year ago

I'm not sure of the implementation, I think the stale should kind of extend the expiration of the cache entries as ttl+stale, so we can still serve the old cached values while running the refresh - I'm not sure, I may be wrong with that.

I've found this https://web.dev/stale-while-revalidate/#whats-it-mean maybe can help

mcollina commented 1 year ago

I'm not sure of the implementation, I think the stale should kind of extend the expiration of the cache entries as ttl+stale, so we can still serve the old cached values while running the refresh - I'm not sure, I may be wrong with that.

Good catch! I'll update the way the ttl and stale parameters compute the final expiration time.

mcollina commented 1 year ago

PTAL, updated.

simone-sanfratello commented 1 year ago

LGTM!