Exemplo n.º 1
0
        private T GetData <E, M, T>(string cacheKey, Func <Func <E, M>, T> getData, Func <E, M> transformData) where T : class
        {
            T data = IsCacheEnabled ? InnerCache.Get <T>(cacheKey) : null;

            if (data == null)
            {
                data = getData(transformData);
            }

            return(data);
        }
Exemplo n.º 2
0
        private T GetData <T>(string cacheKey, Func <T> getData) where T : class
        {
            T data = IsCacheEnabled ? InnerCache.Get <T>(cacheKey) : null;

            if (data == null)
            {
                data = getData();
            }

            return(data);
        }
Exemplo n.º 3
0
        protected override bool TryGetInner <TValue>(string key, out TValue value)
        {
            object val = InnerCache.Get(key, null);

            if (val != null)
            {
                value = Newtonsoft.Json.JsonConvert.DeserializeObject <TValue>(val.ToString());
                return(true);
            }

            value = default(TValue);
            return(false);
        }
Exemplo n.º 4
0
            protected override bool TryGetInner <TValue>(string key, out TValue value)
            {
                var item = InnerCache.Get(key, null) as CacheItem;

                if (item != null)
                {
                    hits++;
                    // ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
                    value = item.Value is TValue ? (TValue)item.Value : default(TValue);
                    return(true);
                }

                misses++;
                value = default(TValue);
                return(false);
            }
Exemplo n.º 5
0
        protected virtual CacheMethodTaken TryGetScopedInner <TValue>(String key, out ScopedValue <TValue> value)
        {
            var directives = CacheDirectives.CurrentScope;

            if (!directives.Method.HasFlag(CacheMethod.Get))
            {
                value = default;
                return(CacheMethodTaken.None);
            }

            if (InnerCache.Get(key, regionName: null) is ScopedValue <TValue> scopedValue &&
                directives.IsInScope(scopedValue))
            {
                value = scopedValue;
                return(CacheMethodTaken.Get);
            }

            value = default;
            return(CacheMethodTaken.GetMiss);
        }
Exemplo n.º 6
0
 public TValue Get(TKey key, Func <TKey, TValue> factory)
 {
     return(InnerCache.Get(key, factory));
 }