Пример #1
0
        public static TResult Get <TResult>(ICache cache, string key, Func2 <TResult> createFunc,
                                            Action <DataKey <TResult> > storeFunc, LinkedCacheDependency dependency)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }

            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            if (createFunc == null)
            {
                throw new ArgumentNullException("createFunc");
            }

            if (storeFunc == null)
            {
                throw new ArgumentNullException("storeFunc");
            }

            var datakey = new LazyDataKey <TResult>(key);

            cache.Get(datakey);
            if (!datakey.HasValue)
            {
                datakey.Value = createFunc();
                storeFunc(datakey);
                if (dependency != null)
                {
                    dependency.Add(key);
                }
            }

            return(datakey.Value);
        }
Пример #2
0
 public static TResult Get <T, TResult>(ICache cache, Func2 <T, TResult> createFunc, T arg, TimeSpan validFor, LinkedCacheDependency dependency)
 {
     return(Get <TResult>(cache, CacheKey(createFunc, arg), () => createFunc(arg),
                          datakey => cache.Store(datakey, validFor), dependency));
 }
Пример #3
0
 public static TResult Get <T, TResult>(ICache cache, Func2 <T, TResult> createFunc, T arg, DateTime expiresAt, LinkedCacheDependency dependency)
 {
     return(Get <TResult>(cache, CacheKey(createFunc, arg), () => createFunc(arg),
                          datakey => cache.Store(datakey, expiresAt), dependency));
 }
Пример #4
0
 public static TResult Get <TResult>(ICache cache, string key, Func2 <TResult> createFunc, TimeSpan validFor, LinkedCacheDependency dependency)
 {
     return(Get <TResult>(cache, key, createFunc,
                          datakey => cache.Store(datakey, validFor), dependency));
 }
Пример #5
0
 public static TResult Get <TResult>(ICache cache, string key, Func2 <TResult> createFunc, DateTime expiresAt, LinkedCacheDependency dependency)
 {
     return(Get <TResult>(cache, key, createFunc,
                          datakey => cache.Store(datakey, expiresAt), dependency));
 }
Пример #6
0
 public static TResult Get <TA, TB, TResult>(ICache cache, Func2 <TA, TB, TResult> createFunc, TA arga, TB argb, LinkedCacheDependency dependency)
 {
     return(Get <TResult>(cache, CacheKey(createFunc, arga, argb), () => createFunc(arga, argb),
                          datakey => cache.Store(datakey), dependency));
 }