public void Intercept(IInvocation invocation) { QCachingAttribute qCachingAttribute = GetQCachingAttributeInfo <QCachingAttribute>(invocation); if (qCachingAttribute != null) { ProceedCaching(invocation, qCachingAttribute); } else { invocation.Proceed(); } }
private void ProceedCaching(IInvocation invocation, QCachingAttribute attribute) { var cacheValue = _cacheManager.Get(cacheKey); if (cacheValue != null) { invocation.ReturnValue = cacheValue; return; } invocation.Proceed(); if (!string.IsNullOrWhiteSpace(cacheKey)) { _cacheManager.Set(cacheKey, invocation.ReturnValue, TimeSpan.FromSeconds(attribute.AbsoluteExpiration)); } }
public void ProceedCaching <T>(IInvocation invocation, T attribute) where T : class { QCachingAttribute attr = attribute as QCachingAttribute; string cacheKey = GenerateCacheKey(invocation); //从缓存中取出的值一律转换成Json字符串 string cacheValue = _cacheMng.Get <string>(cacheKey); if (cacheValue != null) { invocation.ReturnValue = cacheValue; return; } invocation.Proceed(); if (!string.IsNullOrWhiteSpace(cacheKey)) { _cacheMng.Add(cacheKey, invocation.ReturnValue, TimeSpan.FromDays(attr.AbsoluteExpiration), true); } }