Exemplo n.º 1
0
        private Tuple <IList <TElement>, bool> MemoizeCollection <TElement>(
            CacheAddParameters <IList <IBaseCacheKey> > parameters)
            where TElement : class
        {
            IList <TElement> collection = null;
            var result = parameters.Fill(FreshnessRequest.Normal);

            if (result.Item2 || result.Item1 == null)
            {
                return(Tuple.Create(collection, result.Item2));
            }

            var cachedKeys = result.Item1;

            collection = new List <TElement>(cachedKeys.Count);
            foreach (var cachedKey in cachedKeys)
            {
                var element = this.Get <TElement>(cachedKey.Key);

                if (element == null)
                {
                    return(null);   // failed to find one... declare failure and go to backing store
                }
                collection.Add(element);
            }

            // shove the answer-set into the cache only AFTER we validate all the entries.
            parameters.Put(cachedKeys);
            return(Tuple.Create(collection, false));
        }
Exemplo n.º 2
0
        private static Tuple <T, bool> MemoizeElement <T>(CacheAddParameters <T> parameters)
            where T : class
        {
            var result = parameters.Fill(FreshnessRequest.Normal);

            if (result != null && !result.Item2)
            {
                var value = result.Item1;
                parameters.Put(value);
            }

            return(result);
        }