Answer the question
In order to leave comments, you need to log in
How to use CacheDependency in ASP.NET?
I use so cache.
Cache.Get("prefix_"+xxx+"_"+yyyy);
Cache.Insert("prefix_"+xxx+"_"+yyyy, data, null, DateTime.Now.AddSeconds(1), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
prefix_1000_34
prefix_1000_36
prefix_1000_37
prefix_1000_39
prefix_1000_51
prefix_2000_34
prefix_2000_39
prefix_2004_18
prefix_2004_25
prefix_2004_48
Answer the question
In order to leave comments, you need to log in
Try like this
1. Your CacheDependency
class CustomDependencyManager {
class CustomDependency : CacheDependency {
public void Invalidate() {
NotifyDependencyChanged(this, EventArgs.Empty);
}
}
public static CustomDependencyManager Instance = new CustomDependencyManager();
private readonly ConcurrentDictionary<string, CustomDependency> dependencies = new ConcurrentDictionary<string, CustomDependency>();
private CustomDependency GetCacheDependencyInternal(string xxx) {
return dependencies.GetOrAdd(xxx, s => new CustomDependency());
}
public void Invalidate(string xxx) {
GetCacheDependencyInternal(xxx).Invalidate();
}
public CacheDependency For(string xxx) {
GetCacheDependencyInternal(xxx);
}
}
Cache.Insert("prefix_"+xxx+"_"+yyyy, data, CustomDependencyManager.Instance.For(xxx), DateTime.Now.AddSeconds(1), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
...
...
// Пора сбросить кеш
CustomDependencyManager.Instance.Invalidate(xxx);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question