private static void IsEmpty(CachePartition p) { var stats = p.GetStatistics(); stats.Should() .BeEquivalentTo(new CacheStatistics(p.DisplayName, 0, 0, 0, 0)); }
/// <summary> /// Creates <see cref="CachePartition"/> in <see cref="SqlServerDistributedCacheStore"/> using <see cref="CachePartitionDefinition"/> /// </summary> /// <returns><see cref="CachePartition"/> object created in <see cref="SqlServerDistributedCacheStore"/></returns> public ICachePartition CreatePartition(CachePartitionDefinition cachePartitionInfo) { ICachePartition cachePartition = new CachePartition(cachePartitionInfo.Name, cachePartitionInfo.AbsoluteExpiration, cachePartitionInfo.AbsoluteExpirationRelativeToNow, cachePartitionInfo.SlidingExpiration, new DistributedCache(new ExtendedSqlServerCache(Options.Create(CacheOptions)), this), cachePartitionInfo.Priority, cachePartitionInfo.Size); CachePartitions[cachePartitionInfo.Name] = cachePartition; return(cachePartition); }
public T GetItems <T, K>(string key, CachePartition partition, Func <T> getUncachedItems, Func <K, IEnumerable <ICacheEntity> > getDependencies) where T : IEnumerable <K> { HttpContext context = HttpContext.Current; string fullKey = partition != null ? key + partition.ToString() : key; T cacheItem = (T)context.Cache[fullKey]; if (cacheItem != null) { return(cacheItem); } T items = getUncachedItems(); if (items != null) { insert(context, fullKey, items); // partitions if (partition != null) { CacheDependencyList partitionList = context.Cache[key] as CacheDependencyList; if (partitionList == null) { insert(context, key, partitionList = new CacheDependencyList()); } string keyAndPartition = key + partition.ToString(); if (!partitionList.Contains(keyAndPartition)) { partitionList.Add(keyAndPartition); } } // dependencies if (getDependencies != null) { if (items.Count() > 0) { foreach (K item in items) { // add dependencies for each item foreach (ICacheEntity dependency in getDependencies(item)) { cacheDependency(key, context, dependency); } } } else { // allow the caller to add dependencies for dependent objects even though no items were found foreach (ICacheEntity dependency in getDependencies(default(K))) { cacheDependency(key, context, dependency); } } } } return(items); }
public static bool CreateEntry <T>(this CachePartition cache, IPartitionObjectKey key, T value, Action <ICacheEntry> configureEntry = null) { return(cache.CreateEntry(key, value, cache.ClearCacheTokenSource, 10, null, configureEntry)); }