/// <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(); }
/// <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(); }
public LifespanManager(FluidCache <T> owner, int capacity, TimeSpan minAge, TimeSpan maxAge, GetNow getNow) { this.owner = owner; double maxMS = Math.Min(maxAge.TotalMilliseconds, (double)12 * 60 * 60 * 1000); // max = 12 hours this.minAge = minAge; this.getNow = getNow; this.maxAge = TimeSpan.FromMilliseconds(maxMS); validatyCheckInterval = TimeSpan.FromMilliseconds(maxMS / 240.0); // max timeslice = 3 min bagItemLimit = Math.Max(capacity / 20, 1); // max 5% of capacity per bag const int nrBags = 265; // based on 240 timeslices + 20 bags for ItemLimit + 5 bags empty buffer bags = new OrderedAgeBagCollection <T>(nrBags); Stats = new CacheStats(capacity, nrBags, bagItemLimit, minAge, this.maxAge, validatyCheckInterval); OpenBag(0); }
private const int nrBags = 265; // based on 240 timeslices + 20 bags for ItemLimit + 5 bags empty buffer public LifespanManager(FluidCache <T> owner, TimeSpan minAge, TimeSpan maxAge, GetNow getNow) { this.owner = owner; int maxMS = Math.Min((int)maxAge.TotalMilliseconds, 12 * 60 * 60 * 1000); // max = 12 hours this.minAge = minAge; this.getNow = getNow; this.maxAge = TimeSpan.FromMilliseconds(maxMS); validatyCheckInterval = TimeSpan.FromMilliseconds(maxMS / 240.0); // max timeslice = 3 min bagItemLimit = this.owner.Capacity / 20; // max 5% of capacity per bag bags = new AgeBag <T> [nrBags]; for (int loop = nrBags - 1; loop >= 0; --loop) { bags[loop] = new AgeBag <T>(); } OpenCurrentBag(getNow(), 0); }
public LifespanManager(FluidCache <T> owner, int capacity, TimeSpan minAge, TimeSpan maxAge, GetNow getNow) { this.owner = owner; this.minAge = minAge; this.getNow = getNow; this.maxAge = TimeSpan.FromMilliseconds(Math.Min(maxAge.TotalMilliseconds, MaxMaxAge.TotalMilliseconds)); validatyCheckInterval = TimeSpan.FromMilliseconds(Math.Min(maxAge.TotalMilliseconds, MaxInterval.TotalMilliseconds)); bagItemLimit = Math.Max(capacity / PreferedNrOfBags, 1); int nrTimeSlices = (int)(MaxMaxAge.TotalMilliseconds / MaxInterval.TotalMilliseconds); // NOTE: Based on 240 timeslices + 20 bags for ItemLimit + 5 bags empty buffer int nrBags = nrTimeSlices + PreferedNrOfBags + EmptyBagsBuffer; bags = new OrderedAgeBagCollection <T>(nrBags); Stats = new CacheStats(capacity, nrBags, bagItemLimit, minAge, this.maxAge, validatyCheckInterval); OpenBag(0); }