I am trying to get second-level caching for working with entity framework 4. "EF provider wrappers" made by Yarek Kowalski ( http://code.msdn.microsoft.com/EFProviderWrappers/Release/ProjectReleases.aspx?ReleaseId=4747 ) works pretty well , the problem is that all cached records from the table are invalid as soon as the update is done in the table. Is this the goal, or have I made a mistake in my implementation?
If it is intended, this makes it completely useless for tables that contain many updates. Is there any way to fix this?
This is my implementation of the ICache interface using ScaleOut StateServer as a cache:
public class SossCache : ICache { private readonly NamedCache SossCache; public SossCache(string cacheName) { this.SossCache = CacheFactory.GetCache(cacheName); } public bool GetItem(string key, out object value) { value = this.SossCache.Get(key); return value != null; } public void PutItem(string key, object value, IEnumerable<string> dependentEntitySets, TimeSpan slidingExpiration, DateTime absoluteExpiration) { bool isAbsoluteTimeout = slidingExpiration == TimeSpan.Zero; TimeSpan timeout = isAbsoluteTimeout ? absoluteExpiration.Subtract(DateTime.Now) : slidingExpiration; CreatePolicy createPolicy = new CreatePolicy(timeout, isAbsoluteTimeout, ObjectPreemptionPriority.Normal, dependentEntitySets.ToArray(), true); this.SossCache.Insert(key, value, createPolicy, true, false); } public void InvalidateItem(string key) { this.SossCache.Remove(key); } public void InvalidateSets(IEnumerable<string> entitySets) { foreach (string key in entitySets) InvalidateItem(key); } }
source share