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

[Issue] How can I manually expire the cache in the following scenarios? #181

Closed
neozhu opened this issue Oct 28, 2023 · 5 comments
Closed

Comments

@neozhu
Copy link

neozhu commented Oct 28, 2023

Scenario 1:
I have a paginated query for a product table. I need to cache the data whenever users switch pages. Each page switch results in caching of data, where the cache key is defined as key=$"{pageindex}{pagesize}{keywords}". This works as intended.

However, if I execute a delete or insert operation on the Product table, I need to refresh the related cached data for the Product. Here, the paginated query's data usually needs immediate refresh.

Furthermore, if a user has cached data based on a ProductId, and this specific ProductId data has just been modified (for instance, the corresponding product was deleted or updated), that cache should also expire.

How can I achieve manual cache refreshing or expiration in these cases? @jodydonetti

@AaronTorgerson
Copy link

This is asking a lot of a cache library @neozhu. You will need some sort of cache invalidation strategy that keeps track of the types and their associated "primary keys" stored under each cache key. This is probably better handled at a level "above" the cache itself. To do it properly, the cache library would somehow have to know which of the types in the graph of objects you place into a cache bucket can be updated and what their "identity" is (i.e. primary key). Like, what if the cache bucket contained an object of type Order which contained a reference to the updated Product? How would it know, then, what keys to evict? This is not an easy problem to solve and I would think it to be out of scope for a project like FusionCache.

Aside: One major issue to note is that nodes other than the one that performed the SQL update may have in-memory cache keys that it doesn't. This would thus require a pub/sub mechanism to notify the other nodes that, e.g., Product(id=123) was modified in order for them to look up which of their cache keys contained that entity.

@adospace
Copy link

You have to store in a list all the keys you generate.
Every new key is added to the list.
Then after any edit of your product table get that list and expire all the keys.
Should work, hope it helps

@neozhu
Copy link
Author

neozhu commented May 13, 2024

Thanks a lot for your advice.

@jodydonetti
Copy link
Collaborator

UPDATE: it is happening 🥳

Any help would be appreciated!

@jodydonetti
Copy link
Collaborator

Hi all, v2.0.0-preview-1 is out 🥳
This includes Tagging and Clear() support!

🙏 Please, if you can try it out and let me know what you think, how it feels to use it or anything else really: your contribution is essential, thanks!

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

4 participants