Ejemplo n.º 1
0
 /// <summary>Constructor</summary>
 /// <param name="capacity">the normal item limit for cache (Count may exeed capacity due to minAge)</param>
 /// <param name="minAge">the minimium time after an access before an item becomes eligible for removal, during this time
 /// the item is protected and will not be removed from cache even if over capacity</param>
 /// <param name="maxAge">the max time that an object will sit in the cache without being accessed, before being removed</param>
 /// <param name="getNow">A delegate to get the current time.</param>
 /// <param name="validateCache">
 /// An optional delegate used to determine if cache is out of date. Is called before index access not more than once per 10 seconds
 /// </param>
 public FluidCache(int capacity, TimeSpan minAge, TimeSpan maxAge, GetNow getNow, IsValid validateCache = null)
 {
     lifeSpan = new LifespanManager <T>(this, capacity, minAge, maxAge, getNow)
     {
         ValidateCache = validateCache
     };
 }
Ejemplo n.º 2
0
 /// <summary>constructor</summary>
 /// <param name="owner">parent of index</param>
 /// <param name="lifespanManager"></param>
 /// <param name="getKey">delegate to get key from object</param>
 /// <param name="loadItem">delegate to load object if it is not found in index</param>
 public Index(FluidCache <T> owner, int capacity, LifespanManager <T> lifespanManager, GetKey <T, TKey> getKey, ItemLoader <TKey, T> loadItem)
 {
     Debug.Assert(owner != null, "owner argument required");
     Debug.Assert(getKey != null, "GetKey delegate required");
     this.owner           = owner;
     this.lifespanManager = lifespanManager;
     index         = new Dictionary <TKey, WeakReference>(capacity * 2);
     _getKey       = getKey;
     this.loadItem = loadItem;
     RebuildIndex();
 }
Ejemplo n.º 3
0
 /// <summary>constructor</summary>
 /// <param name="owner">parent of index</param>
 /// <param name="lifespanManager"></param>
 /// <param name="getKey">delegate to get key from object</param>
 /// <param name="loadItem">delegate to load object if it is not found in index</param>
 /// <param name="keyEqualityComparer">The equality comparer to be used to compare the keys. Optional.</param>
 public Index(
     FluidCache <T> owner,
     LifespanManager <T> lifespanManager,
     GetKey <T, TKey> getKey,
     ItemCreator <TKey, T> loadItem,
     IEqualityComparer <TKey> keyEqualityComparer)
 {
     Debug.Assert(owner != null, "owner argument required");
     Debug.Assert(getKey != null, "GetKey delegate required");
     this.owner           = owner;
     this.lifespanManager = lifespanManager;
     _getKey                  = getKey;
     this.loadItem            = loadItem;
     this.keyEqualityComparer = keyEqualityComparer;
     RebuildIndex();
 }
Ejemplo n.º 4
0
 /// <summary>constructor</summary>
 public Node(LifespanManager <T> manager, T value)
 {
     this.manager = manager;
     Value        = value;
 }