Removing multiple cache keys based on matching criteria

Topics: Development Team Discussion, User Discussion
Nov 17, 2011 at 5:09 PM
Edited Nov 17, 2011 at 5:09 PM

Hi,

I'm using ent lib 5.0 caching block. My question is How can we remove multiple cache keys based on some matching criteria in on go?

I'm trying something like below code but its giving an error as because "Keys" is not recognised keyword.

public static void RemoveUserSpecificCacheKeys(string cacheUserSpecificKey)
    {
        ICacheManager cache = EnterpriseLibraryContainer.Current.GetInstance<ICacheManager>();

        List<string> keysToRemove = new List<string>();

        foreach (var key in Cache.Keys)
        {
            if (key.Contains(cacheUserSpecificKey))
            {
                keysToRemove.Add(key);
            }
        }

        foreach (var key in keysToRemove)
        {
            cache.Remove(key);
        }
    }

Any Help?

Regards

Bhupinder

Coordinator
Nov 17, 2011 at 5:28 PM

Hi Bhupinder,

For EntLib specific questions (vs EntLibContrib), you'll probably have better support by using the EntLib support forum/distribution list.

But by looking at your code quickly, everything looks fine except the following line ("cache" should be written with lower case "c"):

foreach (var key in cache.Keys)

Cheers,

Jeremi

Nov 18, 2011 at 9:16 AM
Edited Nov 18, 2011 at 9:19 AM

Hi Jeremi,

Thanks for your reply. but even cache.Keys is not recognizable.

Best Rgds

Bhupinder

Nov 18, 2011 at 9:17 AM

Hi Jeremi,

Thanks for your reply. but even cache.Keys is not recognizable.

Best Rgds

Bhupinder