ASP.NET中的缓存看起来像使用某种关联数组:
我不知道整个关键名称.因为似乎有联想
数组在这里,它应该是可能的(?) @H_403_4@任何人都可以帮我找出一种循环存储缓存键的方法
对它们执行简单的逻辑?这就是我所追求的:
@H_403_4@如您所见,对缓存对象执行空检查非常有用. @H_403_4@但是我想实现一个可以清除缓存值的缓存清除功能
- // Insert some data into the cache:
- Cache.Insert("TestCache",someValue);
- // Retrieve the data like normal:
- someValue = Cache.Get("TestCache");
- // But,can be done associatively ...
- someValue = Cache["TestCache"];
- // Also,null checks can be performed to see if cache exists yet:
- if(Cache["TestCache"] == null) {
- Cache.Insert(PerformComplicatedFunctionThatNeedsCaching());
- }
- someValue = Cache["TestCache"];
我不知道整个关键名称.因为似乎有联想
数组在这里,它应该是可能的(?) @H_403_4@任何人都可以帮我找出一种循环存储缓存键的方法
对它们执行简单的逻辑?这就是我所追求的:
- static void DeleteMatchingCacheKey(string keyName) {
- // This foreach implementation doesn't work by the way ...
- foreach(Cache as c) {
- if(c.Key.Contains(keyName)) {
- Cache.Remove(c);
- }
- }
- }