Cached Data Compression: beforeStore and afterRead hooks #3986
neo-reply-lukas
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
Using Caching with Nitro works great, and we have quite a lot of tools at our hands to define our caches.
Recently I was looking into compressing my cached Data, but was unable to find the appropriate hooks.
My idea: add two Hooks to the cache cache:beforeStore and cache:afterRead.
beforeStore would receive the original value to be cached, its return value will be stored in the cache instead of the original one.
afterRead would receive what has been stored in the cache, and its return value would replace the originally stored value on cache reads.
That way, we could easily implement compression, cleanly encapsulated in the cache itself, without affecting any outside component of our apps.
I think there will be more usecases to these hooks, but compression is the main goal i'd like to achieve.
Of course we could write a new storage Layer that handles compression, but by introducing these hooks, compression (and potentially other useful things) could be used with any storage layer already implemented.
Would be glad to hear your opinions and input about it!
I'd be inclined to implement it, if it has a fair chance of being merged :)
Beta Was this translation helpful? Give feedback.
All reactions