示例#1
0
        public async Task <CacheItem> AddAsync()
        {
            var item = new CacheItem()
            {
                Key   = "1",
                Value = "Anderson"
            };

            return(await provider.AddAsync(item));
        }
        public async ValueTask <CacheItem> AddAsync(CacheItem obj)
        {
            if (!obj.IsValidKey())
            {
                throw new InvalidCacheKeyException("object to cache is invalid key not informed!");
            }
            var cacheItem = await _provider.GetAsync(obj.Key);

            if (cacheItem != null)
            {
                throw new DuplicateCacheKeyException($"object with key {obj.Key} already exists!");
            }
            return(await _provider.AddAsync(obj));
        }