public MediumConfiguration(CacheMediumType type, CacheCapacity capacity, IReplacementAlgorithm algorithm) { this.type = type; this.capacity = capacity; this.algorithm = algorithm; }
/// <summary> /// Creates a new instance of the <c>Cache</c> object using the provided number of sets, number of entries and replacement algorithm /// </summary> /// <param name="numSet">The number of sets the <see cref="Cache{TItem, UKey, VData}"/> will have</param> /// <param name="numEntry">The number of entries in each set</param> /// <param name="replacementAlgo">The type of <see cref="IReplacementAlgorithm{TItem, UKey, VData}"/> object that will be used to determine objects that will be replaced when a set is full during a <see cref="Cache{TItem, UKey, VData}.Put(UKey, VData)"/> operation</param> public Cache(int numSet, int numEntry, IReplacementAlgorithm <TItem, UKey, VData> replacementAlgo) { // Check that the key type will work as a hashable type if (!typeof(IEquatable <UKey>).IsAssignableFrom(typeof(UKey))) { throw new ArgumentException("CacheEntry<UKey,VData> key type should implement IEquatable<UKey> generic interface", "UKey"); } // ensure _isOnAccessCacheEntry value _isOnAccessCacheEntry = typeof(IOnAccessCacheEntry).IsAssignableFrom(typeof(TItem)); _numEntry = numEntry; _numSet = numSet; // initialize cache to array of empty objects _cacheArray = Enumerable.Range(0, _numSet * _numEntry).Select(_ => new TItem()).ToArray(); // setup replacement algorithm _replacementFinder = replacementAlgo; }
public CacheMediumBase(string name, CacheCapacity capacity, ILoggerFacade logger) { this.logger = logger; if (this.logger != null) { this.logger.Log("Cache medium " + name + " instance is created.", Category.Info, Priority.Medium); } this.Capacity = capacity; this.name = name; this.algorithm = null; this.next = null; this.previous = null; this.algorithmData = new AlgorithmData(); this.rwLock = new object(); }
public void UpdateAlgorithm(int index, IReplacementAlgorithm algorithm) { if (algorithm == null) { throw new NullReferenceException("algorithm is null."); } if (index < 0 || index >= this.mediumConfigurationList.Count) { throw new IndexOutOfRangeException("index is out of range."); } this.mediumConfigurationList[index].UpdateAlgorithm(algorithm); }
public void UpdateAlgorithm(IReplacementAlgorithm algorithm) { this.algorithm = algorithm; }
private void ValidateReplacementAlgorithm(IReplacementAlgorithm[] algorithms) { if (algorithms == null) { throw new NullReferenceException("algorithm is NULL."); } if (this.mediums.Count != algorithms.Length) { throw new InvalidOperationException("algorithm number is not indentical to medium number."); } }