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

Added a RemoveAll function to clear the entire cache #91

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

migr1
Copy link

@migr1 migr1 commented Oct 1, 2019

Fixes #67
Implemented by internally creating a new IMemoryCache instance.

@lunar-safari
Copy link

This would be great. To have the ability to 'nuke' the entire cache with a simple _cache.RemoveAll() would be very valuable.

@unruledboy
Copy link

When will we merge this PR? I need this in our project.

Thanks.

@genpri
Copy link

genpri commented Jan 16, 2020

This is much needed in our project also.
Any estimation to when its going to be merged?

Thanks.

@rothschild86
Copy link

+1

@Leftyx
Copy link

Leftyx commented Mar 11, 2020

Could you please merge this feature ?

@maranmaran
Copy link

+1

@ArnaudB88
Copy link

ArnaudB88 commented Mar 16, 2020

Does not work correctly in my project (working with dependency injection)

@ArnaudB88
Copy link

The dependency injection code should also be changed.
More specific in:

  • LazyCache/LazyCache.AspNetCore/LazyCacheServiceCollectionExtensions.cs
  • LazyCache/LazyCache.Ninject/LazyCacheModule.cs

How should it be changed? There are 2 options:
Option A: work with a cacheProvider factory function

  • remove registration for IMemoryCache. This is not needed anymore.
  • edit registration for ICacheProvider, keep the singleton lifetime but provide a factory function. Eg.:
    container => new MemoryCacheProvider(() => new MemoryCache(container.Resolve<IOptions<MemoryCacheOptions>>()))

Option B: make IMemoryCache registration with TransientLTM

  • Edit the IMemoryCache registration so the registration is not singleton, but transient. So each resolve will have a new MemoryCache instance. This is needed for the MemoryCacheProvider constructor function.

Both options have the same result.
Personally I prefer option A, so no other code can request an instance of IMemoryCache.

@migr1
Copy link
Author

migr1 commented Mar 31, 2020

@ArnaudB88 Does the new injection code look ok?

@ArnaudB88
Copy link

@ArnaudB88 Does the new injection code look ok?

Looks fine to me. But it's good to let it review by someone else than me. I have experience in other DI containers than Ninject and MS.DI.
But option A looks good to me :)

@svengeance
Copy link
Contributor

@alastairtree Is there anything preventing this from going forward?

@alastairtree
Copy link
Owner

I am still thinking about if, and how, LazyCache should support a delete everything feature. In the meantime I have added 2 ways of achieving the same thing without changes to LazyCache to the docs.

@svengeance
Copy link
Contributor

svengeance commented Sep 20, 2020

@alastairtree Would it be possible for you to publish an update or some high level overview of what your plans are for this project? It'd be cool to see what you think it should do, what it's doing right, what it can do better, etc? This would help me (and others) identify issues and places to come in with PRs

Good to know there are alternatives for emptying the cache as well

@ArnaudB88
Copy link

@alastairtree This pull request is basically your first method to empty the entire cache. In my opinion, a clean and more easy to understand way than method 2.
It just adds a change of passing a MemoryCache function instead of an instance.

@alastairtree
Copy link
Owner

@alastairtree Would it be possible for you to publish an update or some high level overview of what your plans are for this project? It'd be cool to see what you think it should do, what it's doing right, what it can do better, etc? This would help me (and others) identify issues and places to come in with PRs

Very fair - my ability to maintain this project, like all open source is time limited. Key requirements for all changes are that LazyCache should be small, fast and as easy to use as possible, and it should remain current with the latests dot net. In this respect the majority of functionality is done but as you know there are always improvements that can be made. I have done a bunch of housework on the issue list so it is now more manageable and current, and marked many of them as help wanted where PRs would be appreciated so please take a look.

@alastairtree
Copy link
Owner

I have added a long comment detailing some of the challenges with this feature on the issue below which should help explain why it's not yet merged #67 (comment)

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

Successfully merging this pull request may close these issues.

Feature Request provide Flush/Clear operation for entire cache
10 participants