Exemple #1
0
        public void Invalidate(Type classType, string cacheKey)
        {
            var keys     = _cacheProvider.GetKeys();
            var typeName = classType.Name.Replace("Proxy", "");

            cacheKey = $"{typeName}.{cacheKey}";
            var key = keys.FirstOrDefault(x => x.StartsWith(cacheKey));

            if (key == null)
            {
                CachedAttributesOptions.Log("Cannot find key in cache:" + key);
                return;
            }

            _cacheProvider.Remove(key);
        }
Exemple #2
0
        protected override object SyncImpl(IInvocation invocation, CachedAttribute cachedAttribute)
        {
            //eğer o metot cache işlemlerinin yapılması gereken bir metot ise ilk olarak dynamic olarak aşağıdaki gibi bir cacheKey oluşturuyoruz
            var cacheKey = _cachingKeyBuilder.BuildCacheKey(invocation, null);

            CachedAttributesOptions.Log($"{cacheKey}\nStarted intercepting SYNC: ");
            var result = _cacheProvider.GetOrAdd(cacheKey, () =>
            {
                CachedAttributesOptions.Log($"{cacheKey}\nFetching data to cache SYNC");
                invocation.Proceed();
                CachedAttributesOptions.Log($"{cacheKey}\nFetched data to cache SYNC");
                return(invocation.ReturnValue);
            }, cachedAttribute.GetExpires());

            CachedAttributesOptions.Log($"{cacheKey}\nReturning cached data SYNC");
            return(result);
        }
Exemple #3
0
        protected override Task <TResult> AsyncImpl <TResult>(IInvocation invocation,
                                                              IInvocationProceedInfo proceedInfo, CachedAttribute cacheAttribute)
        {
            //eğer o metot cache işlemlerinin yapılması gereken bir metot ise ilk olarak dynamic olarak aşağıdaki gibi bir cacheKey oluşturuyoruz
            var cacheKey = _cachingKeyBuilder.BuildCacheKey(invocation, null);

            CachedAttributesOptions.Log($"{cacheKey}\nStarted intercepting ASYNC: ");
            var result = _cacheProvider.GetOrAddAsync(cacheKey, async() =>
            {
                CachedAttributesOptions.Log($"{cacheKey}\nFetching data to cache ASYNC");
                proceedInfo.Invoke();
                var taskResult   = (Task <TResult>)invocation.ReturnValue;
                var timeoutTask  = taskResult.TimeoutAfter();
                var methodResult = await timeoutTask;
                CachedAttributesOptions.Log($"{cacheKey}\nFetched data to cache ASYNC");
                return(methodResult);
            }, cacheAttribute.GetExpires());

            CachedAttributesOptions.Log($"{cacheKey}\nReturning cached data ASYNC");
            return(result);
        }