Skip to content

Added a RemoveAll function to clear the entire cache#91

Open
migr1 wants to merge 8 commits intoalastairtree:masterfrom
migr1:clear-cache
Open

Added a RemoveAll function to clear the entire cache#91
migr1 wants to merge 8 commits intoalastairtree:masterfrom
migr1:clear-cache

Conversation

@migr1
Copy link
Copy Markdown

@migr1 migr1 commented Oct 1, 2019

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

@lunar-safari
Copy link
Copy Markdown

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
Copy Markdown

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

Thanks.

@genpri
Copy link
Copy Markdown

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
Copy Markdown

+1

@Leftyx
Copy link
Copy Markdown

Leftyx commented Mar 11, 2020

Could you please merge this feature ?

@maranmaran
Copy link
Copy Markdown

+1

@ArnaudB88
Copy link
Copy Markdown

ArnaudB88 commented Mar 16, 2020

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

@ArnaudB88
Copy link
Copy Markdown

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
Copy Markdown
Author

migr1 commented Mar 31, 2020

@ArnaudB88 Does the new injection code look ok?

@ArnaudB88
Copy link
Copy Markdown

@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
Copy Markdown
Contributor

@alastairtree Is there anything preventing this from going forward?

@alastairtree
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
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)

@sonarqubecloud
Copy link
Copy Markdown

migr2 and others added 2 commits March 29, 2026 08:34
Migrated all projects from net48/netstandard2.0/netcoreapp2.2 to net10.0.
Updated Microsoft.Extensions.* packages to 10.0.5, EF Core to 10.0.5,
NUnit to 4.5.1, FluentAssertions to 8.9.0, Test SDK to 18.4.0, Ninject to 3.3.6.
Modernized ASP.NET Core sample (WebApplication.CreateBuilder, AddControllers,
MapControllers, FromSqlRaw). Converted Console.Net461 to SDK-style project.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

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