Esempio n. 1
0
        public TestController(IPartitionedCacheProvider partitionedCacheProvider)
        {
            _partitionedCacheProvider = partitionedCacheProvider;

            _usersCache   = _partitionedCacheProvider.Resolve <string>("Users Cache");
            _usersIdCache = _partitionedCacheProvider.Resolve <int>("UserId Cache");
        }
        public static IPartitionedCacheProvider WithPartition <T>(
            this IPartitionedCacheProvider partitionedCacheProvider,
            string key)
        {
            if (partitionedCacheProvider == null)
            {
                throw new ArgumentNullException("The partitionedCacheProvider cannot be null.");
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException("The key cannot be null, empty or white space.");
            }

            if (!partitionedCacheProvider.TryAddPartition <T>(key))
            {
                throw new InvalidOperationException($"Unable to add the partition with key - {key}");
            }

            return(partitionedCacheProvider);
        }