Skip to content

Composite key support (or cache regions?) #86

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

Closed
WhitWaldo opened this issue Aug 20, 2019 · 3 comments
Closed

Composite key support (or cache regions?) #86

WhitWaldo opened this issue Aug 20, 2019 · 3 comments

Comments

@WhitWaldo
Copy link

WhitWaldo commented Aug 20, 2019

I've been using LazyCache quite happily for over a year now, so thank you for the time you've put into this package.

Today, I have a need for composite key support. I would like to be able to key cache entries by a user identifier and by certain argument values used in a given method. That's easily done by just hashing and concatenating the argument values.

However, I would also like to be able to invalidate based on a partial match of this composite key. For example, should a user's properties update, I would like to be able to invalidate the cached values for this user based on their user identifier even though I don't know the values of the remainder of the cached keys.

Your library doesn't seem to handle this out of the box and after a brief look through your implementation, it doesn't look like you have access to any of the keys stored in the cache via the IMemoryCache. I've considered implementing a dictionary to use as a non-authoritative source for the keys in the cache (not using this in a distributed sense today), but I can also see how this could introduce consistency issues if not handled carefully.

Do you have any other suggestions for going about implementing this? I'd be happy to do the work and eventually submit a pull request, but I'd appreciate your thoughts on it.

@alastairtree
Copy link
Owner

I think the best way to implement this would be to implement some kind of cache regions, where you get a seperate instance of CachingService (and the underlying cache provider) per region. Then to clear all keys in the region, you could just dispose/rebuild the cache service, which is the same as another often request feature - clear all items in the cache. You would just need a way to request your chosen cache region, probably by a string key.

Sound like something that would cover your use case?

@alastairtree alastairtree changed the title Composite key support Composite key support (or cache regions?) Dec 28, 2019
@nilmas
Copy link

nilmas commented Feb 22, 2020

Consider the following if relevant in your context / scenario:
https://stackoverflow.com/questions/8463962/using-multiple-instances-of-memorycache

Referring to above is the conclusion that when working in memory constrainted context the optimal scenario cannot be reached until Microsoft completes its work on cache regions.

@alastairtree
Copy link
Owner

This is a duplicate of #74 and I have added a work around to that card using cancellation tokens for a range of cache items over there, so closing this one.

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

No branches or pull requests

3 participants