public static void VisitCacheItems(this IReplacementHandler <CacheKey, CacheValue> ReplacementHandler, IEnumerable <CacheItem <CacheKey, CacheValue> > itemsToVisit)
 {
     foreach (var item in itemsToVisit)
     {
         ReplacementHandler.NotifyCacheItemRetrieved(item);
     }
 }
        public static List <CacheItem <CacheKey, CacheValue> > AddBulkCacheItems(this IReplacementHandler <CacheKey, CacheValue> ReplacementHandler, int numberOfKeyToAdd)
        {
            var itemsAdded = new List <CacheItem <CacheKey, CacheValue> >();

            for (int i = 0; i < numberOfKeyToAdd; i++)
            {
                var cacheItem = Helper.BuildCacheItem($"key{i}", $"value{i}");
                ReplacementHandler.NotifyCacheItemAdded(cacheItem);
                itemsAdded.Add(cacheItem);
            }

            return(itemsAdded);
        }
Beispiel #3
0
 /// <summary>
 /// Creates cache with provided replacement handler.
 /// </summary>
 /// <param name="size">Maximum number of items cache can contain.</param>
 /// <param name="replacementHandler">ReplacementHandler to find cache item to remove when cache is full.</param>
 public DirectMapCache(int size, IReplacementHandler <TKey, TValue> replacementHandler)
 {
     _replacementHandler = replacementHandler;
     _cacheDictionary    = new ConcurrentDictionary <TKey, TValue>();
     Size = size;
 }