コード例 #1
0
        internal CacheStrategy <T> Complete <T>()
        {
            var copy = new CacheStrategy <T>(Cache, BaseKey);

            copy.CopyFrom(this);
            return(copy);
        }
コード例 #2
0
        /// <summary>
        /// Specifies a data retrieval strategy if the desired value does not exist in the cache or is invalid
        /// </summary>
        /// <param name="retrieve">A delegate that specifies how the value is to be retrieved</param>
        /// <returns>An updated cache strategy that includes the retrieval strategy</returns>
        public CacheStrategy <T> RetrieveUsing <T>(Func <P1, T> retrieve)
        {
            CacheStrategy <T> strategy = base.Complete <T>();
            var p1 = strategy.GetParameter <P1>(0);

            strategy.RetrieveCallback = () => retrieve(p1);

            return(strategy);
        }
コード例 #3
0
        /// <summary>
        /// Gets all cached items
        /// </summary>
        public IList <CachedValue <TResult> > GetAll()
        {
            var keysToLoad = Keys.ToList();
            var results    = new List <CachedValue <TResult> >(Keys.Count);

            foreach (TKey key in Keys)
            {
                string itemKey = GetItemKey(key);
                CacheStrategy <TResult> itemStrategy = new CacheStrategy <TResult>(Cache, itemKey).WithRegion(Region);

                if (ValidateCallback != null)
                {
                    itemStrategy = itemStrategy.Validate(ValidateCallback);
                }

                CachedValue <TResult> cachedValue = itemStrategy.Get();
                if (cachedValue != null)
                {
                    keysToLoad.Remove(key);
                    results.Add(cachedValue);
                }
            }

            if (RetrieveCallback != null)
            {
                ICollection <KeyValuePair <TKey, TResult> > newResults = RetrieveCallback(keysToLoad);

                foreach (KeyValuePair <TKey, TResult> result in newResults)
                {
                    string  itemKey = GetItemKey(result.Key);
                    TResult value   = result.Value;

                    CachedValue <TResult> cachedValue = Cache.Set(itemKey, Region, value, Expiration);

                    results.Add(cachedValue);
                }
            }

            return(results);
        }
コード例 #4
0
 internal virtual void CopyFrom(CacheStrategy other)
 {
     this.DefaultExpiration = other.DefaultExpiration;
     this.Region            = other.Region;
     this.Parameters        = other.Parameters?.ToList();
 }
コード例 #5
0
        /// <summary>
        /// Gets the cached value
        /// </summary>
        /// <returns>The cached value</returns>
        public T GetValue <T>()
        {
            CacheStrategy <T> copy = Complete <T>();

            return(copy.GetValue());
        }
コード例 #6
0
 internal virtual void CopyFrom(CacheStrategy other)
 {
     this.Expiration = other.Expiration;
     this.Region     = other.Region;
     this.Parameters = other.Parameters == null ? null : other.Parameters.ToList();
 }