EasyCaching icon indicating copy to clipboard operation
EasyCaching copied to clipboard

Delete All Keys

Open Edgaras91 opened this issue 2 years ago • 4 comments

Description

How can I delete all keys with the correct prefix that was set up in set-up code. For example:

UseRedis( options => options.DBConfig.KeyPrefix = "dev1"

I want to delete all keys that have the above prefix "dev1" without having to mention the KeyPrefix.

I was very surprised that IEasyCachingProvider.RemoveAllAsync() requires keys? What is the use case to use this? Could we have an overload that doesn't take keys as parameters?

I also don't want to use "Flush" method as I believe that will ignore the prefix and require admin config.

The sole reason we are trying this library, as opposed to IDistributedCache, is so we can have a way to clear all cache for the application.

IEasyCachingProvider

Specifications

  • Provider : IEasyCachingProvider
  • Serializer : Newtonsoft
  • System : Windows 11

Edgaras91 avatar Oct 30 '23 16:10 Edgaras91

@Edgaras91 Thanks for your interest in this project.

You can have a try with RemoveByPatternAsync or RemoveByPrefixAsync

catcherwong avatar Oct 31 '23 00:10 catcherwong

@Edgaras91 Thanks for your interest in this project.

You can have a try with RemoveByPatternAsync or RemoveByPrefixAsync

Could you give an example of how to do it? I could not find any good documentation on this. Our key has no structure. Star characters alone were rejected.

Edgaras91 avatar Oct 31 '23 08:10 Edgaras91

@Edgaras91 Thanks for your interest in this project. You can have a try with RemoveByPatternAsync or RemoveByPrefixAsync

Could you give an example of how to do it? I could not find any good documentation on this. Our key has no structure. Star characters alone were rejected.

You can try to look at these unit test codes: https://github.com/easycaching-contrib/ec-basetest/blob/main/src/EasyCaching.BaseTest/BaseCachingProviderTest.cs#L929

Memoyu avatar Nov 18 '23 03:11 Memoyu

Seems like not possible to remove all keys.

On Sat, 18 Nov 2023, 03:18 Memoyu, @.***> wrote:

RemoveByPatternAsync

You can try to look at these unit test codes:

https://github.com/easycaching-contrib/ec-basetest/blob/main/src/EasyCaching.BaseTest/BaseCachingProviderTest.cs#L929

— Reply to this email directly, view it on GitHub https://github.com/dotnetcore/EasyCaching/issues/502#issuecomment-1817346416, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHV6EK5GCLGNAYKJG7W2ZWDYFASIHAVCNFSM6AAAAAA6WKTO2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJXGM2DMNBRGY . You are receiving this because you were mentioned.Message ID: @.***>

Edgaras91 avatar Nov 18 '23 11:11 Edgaras91