Example #1
0
        public override void OnSuccess(MethodExecutionArgs eventArgs)
        {
            string key   = eventArgs.MethodExecutionTag as string;
            string group = GetGroupName(eventArgs.Method);

            if (key == null)
            {
                return;
            }
            object returnValue = eventArgs.ReturnValue;

            if (returnValue != null)
            {
                if (m_Expiration == ExpirationType.AbsoluteTime)
                {
                    CacheFactory.GetInstance(CacheName).Set(key, returnValue, DateTime.Now.Add(m_ExpireTime), group);
                }
                else if (m_Expiration == ExpirationType.SlidingTime)
                {
                    CacheFactory.GetInstance(CacheName).Set(key, returnValue, m_ExpireTime, group);
                }
                else
                {
                    CacheFactory.GetInstance(CacheName).Set(key, returnValue, group);
                }
            }
            CacheStatisticManager.NotHit(eventArgs.Method, CacheName, group);
        }
Example #2
0
        public CacheStatisticItem GetStatisticByMethod(string methodName)
        {
            CacheStatistic en = CacheStatisticManager.GetStatisticByMethod(methodName);

            if (en != null)
            {
                return(Convert(en, methodName));
            }
            return(null);
        }
Example #3
0
        public CacheStatisticItemList GetAllStatistic()
        {
            Dictionary <string, CacheStatistic> list = CacheStatisticManager.GetAllStatistic();
            CacheStatisticItemList rst = new CacheStatisticItemList(list.Count);

            foreach (var entry in list)
            {
                rst.Add(Convert(entry.Value, entry.Key));
            }
            rst.Sort(new Comparison <CacheStatisticItem>((i1, i2) => i1.HitRate == i2.HitRate ? 0 : (i1.HitRate > i2.HitRate ? 1 : -1)));
            return(rst);
        }
Example #4
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));
            }
        }