/// <summary> /// Caches the invocation. /// </summary> /// <param name="invocation">The invocation.</param> /// <param name="cacheKeyProvider">The cache key provider.</param> /// <param name="cacheItemSerializer">The cache item serializer.</param> /// <param name="cacheStorageMode">The cache storage mode.</param> private void CacheInvocation(IInvocation invocation, ICacheKeyProvider cacheKeyProvider, ICacheItemSerializer cacheItemSerializer) { string hash = cacheKeyProvider.GetCacheKeyForMethod(invocation.InvocationTarget, invocation.MethodInvocationTarget, invocation.Arguments); string hashedObjectDataType = string.Format(HASHED_DATA_TYPE_FORMAT, hash); var cacheProvider = CacheProviderFactory.Default.GetCacheProvider(); Type type = cacheProvider[hashedObjectDataType] as Type; object data = null; if (type != null && cacheProvider[hash] != null) data = cacheItemSerializer.Deserialize(cacheProvider[hash].ToString(), type, invocation.InvocationTarget, invocation.Method, invocation.Arguments); if (data == null) { invocation.Proceed(); data = invocation.ReturnValue; if (data != null) { cacheProvider.Add(hashedObjectDataType, invocation.Method.ReturnType); cacheProvider.Add(hash, cacheItemSerializer.Serialize(data, invocation.InvocationTarget, invocation.Method, invocation.Arguments)); } } else invocation.ReturnValue = data; }
/// <summary> /// Forcefully remove one or more entries from the cache. Note that this /// is currently a O(n^2) operation (i.e. it might be slow). /// </summary> /// <param name="objects">The objects to remove from the cache.</param> public static void Remove(params object[] objects) { Check.VerifyNotNull(objects, Error.NullParameter, "objects"); // determine which cache to use CacheStore cacheStore = GetCacheStore(CacheContentType.Entity); // access cache cacheStore.Lock.AcquireWriterLock(rwLockTimeOut); try { if (objects != null && objects.Length > 0) { foreach (object obj in objects) { if (obj is ICacheKeyProvider) { ICacheKeyProvider ckp = obj as ICacheKeyProvider; cacheStore.Remove(ckp.CacheKey); } else { cacheStore.RemoveObject(obj); } } } } finally { cacheStore.Lock.ReleaseWriterLock(); } }
/// <summary> /// Caches the invocation. /// </summary> /// <param name="invocation">The invocation.</param> /// <param name="cacheKeyProvider">The cache key provider.</param> /// <param name="cacheItemSerializer">The cache item serializer.</param> /// <param name="cacheStorageMode">The cache storage mode.</param> private void CacheInvocation(IInvocation invocation, ICacheKeyProvider cacheKeyProvider, ICacheItemSerializer cacheItemSerializer) { string hash = cacheKeyProvider.GetCacheKeyForMethod(invocation.InvocationTarget, invocation.MethodInvocationTarget, invocation.Arguments); string hashedObjectDataType = string.Format(HASHED_DATA_TYPE_FORMAT, hash); var cacheProvider = CacheProviderFactory.Default.GetCacheProvider(); Type type = cacheProvider[hashedObjectDataType] as Type; object data = null; if (type != null && cacheProvider[hash] != null) { data = cacheItemSerializer.Deserialize(cacheProvider[hash].ToString(), type, invocation.InvocationTarget, invocation.Method, invocation.Arguments); } if (data == null) { invocation.Proceed(); data = invocation.ReturnValue; if (data != null) { cacheProvider.Add(hashedObjectDataType, invocation.Method.ReturnType); cacheProvider.Add(hash, cacheItemSerializer.Serialize(data, invocation.InvocationTarget, invocation.Method, invocation.Arguments)); } } else { invocation.ReturnValue = data; } }
public CachedCommandDispatcher(ICacheKeyProvider cacheKeyProvider, IFrameworkCommandDispatcher commandDispatcher, ICacheOptionsProvider cacheOptionsProvider, ICacheAdapter cacheAdapter) { _cacheKeyProvider = cacheKeyProvider; _commandDispatcher = commandDispatcher; _cacheOptionsProvider = cacheOptionsProvider; _cacheAdapter = cacheAdapter; }
/// <summary> /// Sets up the cache with the specified cache key provider /// </summary> /// <param name="resolver">The dependency resolver</param> /// <param name="cacheKeyProvider">Instance of a cache key provider</param> /// <param name="replaceDefaultCommandDispatcher">If true then the default ICommandDispatcher will be replaced with the caching variant</param> /// <param name="options">Cache options</param> /// <returns>The dependency resolver</returns> public static ICommandingDependencyResolver UseCommandCache( this ICommandingDependencyResolver resolver, ICacheKeyProvider cacheKeyProvider, bool replaceDefaultCommandDispatcher, params CacheOptions[] options) { ICacheOptionsProvider cacheOptionsProvider = new CacheOptionsProvider(options); resolver.RegisterInstance(cacheOptionsProvider); if (replaceDefaultCommandDispatcher) { resolver.TypeMapping <ICommandDispatcher, CachedCommandDispatcher>(); } else { resolver.TypeMapping <ICachedCommandDispatcher, CachedCommandDispatcher>(); } resolver.RegisterInstance(cacheKeyProvider); return(resolver); }
/// <summary> /// Sets up the cache with the specified cache key provider /// </summary> /// <param name="resolver">The dependency resolver</param> /// <param name="cacheKeyProvider">Instance of a cache key provider</param> /// <param name="options">Cache options</param> /// <returns>The dependency resolver</returns> public static ICommandingDependencyResolver UseCommandCache(this ICommandingDependencyResolver resolver, ICacheKeyProvider cacheKeyProvider, params CacheOptions[] options) { return(UseCommandCache(resolver, cacheKeyProvider, false, options)); return(resolver); }
public CacheInterceptor(ICacheProvider cacheProvider, ICacheKeyProvider cacheKeyProvider, IApplicationSettingsProvider applicationSettingsProvider) { _cacheProvider = cacheProvider; _cacheKeyProvider = cacheKeyProvider; _applicationSettingsProvider = applicationSettingsProvider; }
/// <summary> /// Insert an entry into the cache using <see cref="CacheStrategy.Temporary"/>. /// </summary> /// <param name="obj">The item to add to the cache.</param> public static void Insert( ICacheKeyProvider obj ) { Insert( obj.CacheKey, obj, CacheStrategy.Temporary ); }
public void Initialize() { CacheKeyProvider = new TCacheKeyProvider(); }
/// <summary> /// Insert an entry into the cache using <see cref="CacheStrategy.Temporary"/>. /// </summary> /// <param name="obj">The item to add to the cache.</param> public static void Insert(ICacheKeyProvider obj) { Insert(obj.CacheKey, obj, CacheStrategy.Temporary); }