gin-cache
gin-cache copied to clipboard
Need a way to invalidate a key/reset cache when updates are made to the cached resources.
Need a way to invalidate a key/reset cache when updates are made to the cached resources.
For eg: if the resource is cached, and one of the resource properties is updated, we need to update the resource in the cache. Otherwise, the changes do not get reflected.
I am unsure if this is already possible, but if it is, an example of how to do this would greatly help.
Maybe you can use the CacheStore.Delete or CacheStore.Set directly? https://github.com/chenyahui/gin-cache/blob/main/persist/cache.go#L20
Maybe you can use the CacheStore.Delete or CacheStore.Set directly? https://github.com/chenyahui/gin-cache/blob/main/persist/cache.go#L20
Yes, For now, I have done like that.
It would be better to expose the default CacheStrategy
so that it can be used for this purpose. Another option is to implement a custom CacheStrategy
. But it is not that simple. This means one has to implement/duplicate CacheKey
generator function as well.
It would be nice to expose these functions so that consumer code can use them to generate the CacheKeys
and invoke CacheStore.Delete
or CacheStore.Set
as you suggested. This avoids duplication of default behavior.
That is indeed a good suggestion, and I will consider implementing it as soon as possible. If you have the time, feel free to submit a pull request as well.
@chenyahui Thank you. Looking forward to the implementation.