/// <summary> /// Puts the specified value in the cache. /// </summary> /// <param name="key">The cache key.</param> /// <param name="value">The value to put into the cache.</param> /// <param name="ttl">The time-to-live for the cache entry.</param> public void Put(string key, object value, Ttl ttl) { if (value != null) { _wrappedCacheProvider.Put(key, _serializer.Serialize(value), ttl); } }
/// <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; } }
protected virtual string SerializeArgument( string argumentName, object argumentValue, ICacheItemSerializer <object, string> serializer, MethodInfo methodInfo, IDictionary <string, Type> parameterTypes, IDictionary <string, object> arguments) { return(serializer.Serialize(argumentValue)); }
/// <summary> /// Puts the specified value in the cache asynchronously. /// </summary> /// <param name="key">The cache key.</param> /// <param name="value">The value to put into the cache.</param> /// <param name="ttl">The time-to-live for the cache entry.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <param name="continueOnCapturedContext">Whether async calls should continue on a captured synchronization context.</param> /// <returns>A <see cref="Task" /> which completes when the value has been cached.</returns> public async Task PutAsync(string key, object value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) { await _wrappedCacheProvider.PutAsync( key, _serializer.Serialize(value), ttl, cancellationToken, continueOnCapturedContext ).ConfigureAwait(continueOnCapturedContext); }
/// <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; }