Esempio n. 1
0
        public T Get <T>(string key)
        {
            var datakey = new LazyDataKey <T>(key);

            Get(datakey);
            return(datakey.Value);
        }
Esempio n. 2
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);
        }