Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a way to invalidate a key/reset cache when updates are made to the cached resources. #34

Open
kumarom opened this issue Nov 10, 2023 · 4 comments
Assignees

Comments

@kumarom
Copy link

kumarom commented Nov 10, 2023

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.

@chenyahui
Copy link
Owner

Maybe you can use the CacheStore.Delete or CacheStore.Set directly? https://github.com/chenyahui/gin-cache/blob/main/persist/cache.go#L20

@kumarom
Copy link
Author

kumarom commented Nov 13, 2023

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.

@chenyahui
Copy link
Owner

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 chenyahui self-assigned this Nov 18, 2023
@kumarom
Copy link
Author

kumarom commented Nov 20, 2023

@chenyahui Thank you. Looking forward to the implementation.

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

No branches or pull requests

2 participants