Exemplo n.º 1
0
        public IPartitionedCache <T> Resolve <T>(string key)
        {
            if (!CachePartitions.TryGetValue(key, out var partitionedCache))
            {
                throw new InvalidOperationException($"Cannot insert a cache partition with the same key {key}");
            }

            return((IPartitionedCache <T>)partitionedCache);
        }
Exemplo n.º 2
0
        public bool TryAddPartition <T>(string key, MemoryCacheOptions memoryCacheOptions = null)
        {
            if (CachePartitions.TryGetValue(key, out _))
            {
                return(false);
            }

            if (memoryCacheOptions == null)
            {
                CachePartitions.Add(key, new PartitionedCache <T>(new MemoryCache(new MemoryCacheOptions())));
            }
            else
            {
                CachePartitions.Add(key, new PartitionedCache <T>(new MemoryCache(memoryCacheOptions)));
            }

            return(true);
        }