Beispiel #1
0
        /// <summary>
        /// Searches the cache for an entity with the specified key using the optional
        /// entity retriever delegate to fetch or construct the entity if it is not present
        /// in the cache.  This override accepts a specific entity lifespan.
        /// </summary>
        /// <param name="key">The key used to identify the entity in the cache.</param>
        /// <param name="retriever">The entity retriever delegate or <c>null</c>.</param>
        /// <param name="lifespan">The maximum duration that a retreive entities should remain in the cache.</param>
        /// <returns>The cached or retreived entity or <c>null</c> if it could not be found or retrieved.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="key" /> is <c>null</c>.</exception>
        public TEntity Get(TKey key, PersistedEntityRetriever <TEntity> retriever, TimeSpan lifespan)
        {
            TEntity entity;

            entity = Get(key);
            if (entity != null)
            {
                return(entity);
            }

            if (retriever == null)
            {
                return(null);
            }

            entity = retriever();
            if (entity == null)
            {
                return(null);
            }

            Add(key, entity, lifespan);

            return(entity);
        }
Beispiel #2
0
 /// <summary>
 /// Searches the cache for an entity with the specified key using the optional
 /// entity retriever delegate to fetch or construct the entity if it is not present
 /// in the cache.  This override uses the default entity lifespan.
 /// </summary>
 /// <param name="key">The key used to identify the entity in the cache.</param>
 /// <param name="retriever">The entity retriever delegate or <c>null</c>.</param>
 /// <returns>The cached or retreived entity or <c>null</c> if it could not be found or retrieved.</returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="key" /> is <c>null</c>.</exception>
 public TEntity Get(TKey key, PersistedEntityRetriever <TEntity> retriever)
 {
     return(Get(key, retriever, defTTL));
 }