unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
6.09k stars 500 forks source link

Actively gc cache entries with ttl on supported storage backends #2378

Open pi0 opened 6 months ago

pi0 commented 6 months ago

Context: Followup from a discussion with @Atinux as he asked if it is possible to pass custom transaction options to defineCachedHandlerto allow setItem with custom ttl and allow invalidating caches. currently, some unstorage drivers support ttl inconsistently.


Currently, the caching layer, passively (on demand) invalidates cache entries on the next access. But it does not delete them during revalidation or in the background.

Actively (automatically by storage backend) invalidating caches, is pending for universal ttl support, which afterward, we can set it.

We might also find a strategy for passive invalidation (during revalidation if it fails for example) but not sure. Another option is for unstorage to support background gc.

sandros94 commented 9 hours ago

I imagine the plan is to pass maxAge (if, for example swr: false) as the ttl for that setItem right?