コード例 #1
0
        private async Task <T> ExcuteAddAsyncFunction <T>(Task <T> task, CacheAttribute cacheAttribute)
        {
            var result = await task;

            AddCache(result, cacheAttribute);
            return(result);
        }
コード例 #2
0
        private void AddCache(object value, CacheAttribute cacheAttribute)
        {
            var cacheValue = _jsonSerializer.Serialize(value);

            if (cacheAttribute.CacheType == 0)
            {
                _cache.SimpleAddSlidingCache(cacheAttribute.CacheName, cacheValue, TimeSpan.FromMilliseconds(cacheAttribute.Millisecond));
            }
            else
            {
                _cache.SimpleAddAbsoluteCache(cacheAttribute.CacheName, cacheValue, DateTime.Now.AddMilliseconds(cacheAttribute.Millisecond));
            }
        }
コード例 #3
0
 public void ExcuteRemove(IInvocation invocation, CacheAttribute cacheAttribute)
 {
     try
     {
         invocation.Proceed();
         _cache.SimpleRemoveCache(cacheAttribute.CacheName);
     }
     catch
     {
         _cache.SimpleRemoveCache(cacheAttribute.CacheName);
         throw;
     }
 }
コード例 #4
0
 private async Task <T> ExcuteRemoveAsyncFunction <T>(Task <T> task, CacheAttribute cacheAttribute)
 {
     try
     {
         var result = await task;
         _cache.SimpleRemoveCache(cacheAttribute.CacheName);
         return(result);
     }
     catch
     {
         _cache.SimpleRemoveCache(cacheAttribute.CacheName);
         throw;
     }
 }
コード例 #5
0
 private async Task ExcuteRemoveAsync(IInvocation invocation, CacheAttribute cacheAttribute)
 {
     try
     {
         invocation.Proceed();
         await(Task) invocation.ReturnValue;
         _cache.SimpleRemoveCache(cacheAttribute.CacheName);
     }
     catch
     {
         _cache.SimpleRemoveCache(cacheAttribute.CacheName);
         throw;
     }
 }
コード例 #6
0
        /// <summary>
        /// 执行异步方法
        /// </summary>
        /// <param name="invocation"></param>
        /// <param name="cacheAttribute">缓存标记</param>
        /// <param name="functionType">1 新增或修改 2 移除</param>
        private void ExecuteHandleAsyncWithResultUsingReflection(IInvocation invocation, CacheAttribute cacheAttribute)
        {
            invocation.Proceed();
            var resultType = invocation.Method.ReturnType.GetGenericArguments()[0];

            if (cacheAttribute.CacheAction == CacheAction.Remove)
            {
                var method = _HandleRemoveAsyncMethodInfo.MakeGenericMethod(resultType);
                invocation.ReturnValue = method.Invoke(this, new[] { invocation.ReturnValue, cacheAttribute });
            }
            else if (cacheAttribute.CacheAction == CacheAction.AddOrUpdate)
            {
                var mi = _HandleAddAsyncMethodInfo.MakeGenericMethod(resultType);
                invocation.ReturnValue = mi.Invoke(this, new[] { invocation.ReturnValue, cacheAttribute });
            }
        }