public override void OnEntry(MethodExecutionArgs eventArgs)
        {
            string key   = CacheKeyGenerator.GenerateKeyName(eventArgs.Method, eventArgs.Arguments.ToArray(), m_Keys);
            object value = key != null?CacheFactory.GetInstance(CacheName).Get(key) : null;

            if (value == null)
            {
                eventArgs.MethodExecutionTag = key;
            }
            else
            {
                eventArgs.ReturnValue  = value;
                eventArgs.FlowBehavior = FlowBehavior.Return;
                CacheStatisticManager.Hit(eventArgs.Method, CacheName, GetGroupName(eventArgs.Method));
            }
        }
示例#2
0
 public override void OnExit(MethodExecutionArgs eventArgs)
 {
     if ((m_Keys != null && m_Keys.Count > 0))
     {
         MethodInfo cacheMethod = m_Type.GetMethod(m_MethodName);
         string     key;
         if (m_CacheGroupName == null) // 缓存的方法没有指定Key的,整个方法就一个Key
         {
             key = CacheKeyGenerator.GenerateKeyName(cacheMethod, eventArgs.Arguments.ToArray(), null);
         }
         else
         {
             key = CacheKeyGenerator.GenerateKeyName(cacheMethod, eventArgs.Arguments.ToArray(), m_Keys);
         }
         if (key != null)
         {
             CacheFactory.GetInstance(m_CacheName).Remove(key);
         }
     }
     else // 刷新缓存的方法没有指定Key
     {
         if (m_CacheGroupName == null)  // 缓存的方法没有指定Key的,整个方法就一个Key
         {
             MethodInfo cacheMethod = m_Type.GetMethod(m_MethodName);
             string     key         = CacheKeyGenerator.GenerateKeyName(cacheMethod, eventArgs.Arguments.ToArray(), null);
             if (key != null)
             {
                 CacheFactory.GetInstance(m_CacheName).Remove(key);
             }
         }
         else
         {
             CacheFactory.GetInstance(m_CacheName).RemoveByGroup(m_CacheGroupName);
         }
     }
 }