Beispiel #1
0
        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));
            }
        }
Beispiel #2
0
        public string CacheRemoveByMethodName(string cacheName, string methodName)
        {
            string[]   array        = methodName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            string     fullName     = string.Join(".", array, 0, array.Length - 1);
            string     assemblyName = string.Join(".", array, 0, array.Length - 2);
            string     method       = array[array.Length - 1];
            Type       type         = Type.GetType(fullName + ", " + assemblyName);
            MethodInfo me           = type.GetMethod(method);
            string     group        = CacheKeyGenerator.GenerateGroupName(me);
            string     key          = CacheKeyGenerator.GenerateKeyName(me, null, null);
            ICache     cache        = CacheFactory.GetInstance(cacheName);

            cache.Remove(key);
            cache.RemoveByGroup(group);
            return("Succeed");
        }
Beispiel #3
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);
         }
     }
 }