-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
How to Invalidate a Cache item using Polly [Add Remove and RemoveAsync to cache provider interfaces] #660
Comments
Hi @jaumemilian . Polly does not provide a specific API for evicting cache entries. So far, it takes the view that, when you created the cache Policy, you had access to the underlying cache ( We could happily add Then, We would also have to update the two cache providers from the App-vNext team, to match those changes: Polly.Caching.MemoryCache and Polly.Caching.IDistributedCache. Marking this up-for-grabs, as it's a great first issue for anyone to take on! (I am focusing on pushing out Distributed Circuit Breaker at the moment.) |
Hi, |
@komalg1 Thanks! I'll aim to add some more notes in the next couple of days/as soon as I can get time. |
Thanks again @komalg1 for offering to contribute! First, see our general notes on Git workflow and configuring line endings. If this is your first open source contribution, google can return lots of general guidance on beginning contributing to OSS - but do fire away with any specific questions. I'm not sure how familiar you are with Polly, so if any of the below is too obvious, bear with me. The below looks to me like a route through what's needed, but if something isn't making sense, feel free to ask more questions; or if it doesn't look like a good first issue, again, feel free to say. Start
At this point the Make cache policy classes have Remove methods chaining on to cache provider Remove methods
Again, at this point the Unit tests
|
@reisenberger thanks for the notes. Correct me if I am wrong but what I understood is that we want to add a functionality to remove a key from the cache if it is no more valid? [edit] I took the code from branch v712-or-v720, I am not able to see 'ISyncCachePolicy' and 'ISyncCachePolicy'. Are these interfaces already existing ? |
Hi, First of all, thanks for your offer to develop that. Let me try to clarify what was my first request looking for: In the IDistributedCache, there is already a mechanism to remove cache entries if you know the key of the entry you want to remove.
What I was looking for in my question was a nice feature that is available for the IMemoryCache, where you can associate several cache entries to one "CancellationTokenSource", and just cancelling that CancellationTokenSource, all the cache entries associated are automatically removed from the cache https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.memory.memorycacheentryextensions.addexpirationtoken?view=aspnetcore-2.2 We can't find that feature in the IDistriburedCache, and I just was wondering if could be Polly was offering on top of IDistributedCache something similar to that Kind Regards, |
@jaumemilian Thanks for the extra detail. No, Polly does not provide that. (I would consider that an interesting separate project, but outside the scope of Polly.) |
Hi @komalg1
👍
perfect!
Thanks for +1 👀 spotting what I missed! Those interfaces are not yet there; they would need adding. Looking at the patterns again, we would need:
and then:
Thus: Thanks for spotting this; let me know if anything else doesn't seem right! |
The extra interfaces mentioned in the above comment have now been added, for Polly v8.0.0, by #739, in the v8.0.0 branch. If anyone continues to pick up this issue as an up-for-grabs, build on the v8.0.0 (or later) branch. Thanks! |
Hi, I would like to pick this ticket up if no one is currently working on it. |
We now have a PR #745 fulfilling this, so it is no longer up-for-grabs. |
When Polly v8.0.0 is released, the following cache providers will need to be updated to the new interfaces in #745 (ie add trivial |
It would be nice if there were a delegate or event to subscribe to for evicting entries. This would allow you to implement the Observer Design Pattern to send events that the Polly Policy could subscribe to for cache eviction. Or, even a custom attribute that could be added to a method that would cause cache entries to be evicted upon that method being called. @dreisenberger Any suggestions for implementing this before my aspirations mentioned above are considered? |
This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made. |
@reisenberger bump |
This issue, as described, is not going to be part of Polly v8. A future version may invest in a new caching policy that builds on top of the MS cache implementation, which is linked to the issue to consider this use case if and when such work happens. |
We are using Cache system with Polly in our NetCore solution and we can't find the way to invalidate specific cache registries.
When using IMemoryCache from NetCore we were able to do it using CancellationTokenSource
This is an example about what we are doing to Cache an HttpClient Request using Polly:
The text was updated successfully, but these errors were encountered: