Exemple #1
0
        public Task InsertOrUpdateItemAsync(string key, byte[] data, DistributedCacheEntryOptions options, CancellationToken token)
        {
            TableCacheEntity cacheEntity = new TableCacheEntity(_partitionKey, key, data, options);
            TableOperation   operation   = TableOperation.InsertOrReplace(cacheEntity);

            return(_cloudTable.ExecuteAsync(operation, token));
        }
Exemple #2
0
        public void InsertOrUpdateItem(string key, byte[] data, DistributedCacheEntryOptions options)
        {
            TableCacheEntity cacheEntity = new TableCacheEntity(_partitionKey, key, data, options);
            TableOperation   operation   = TableOperation.InsertOrReplace(cacheEntity);

            _cloudTable.Execute(operation);
        }
Exemple #3
0
        public async Task RemoveItemAsync(string key, CancellationToken token)
        {
            TableCacheEntity cacheEntity = await RetrieveItemAsync(key, token);

            if (cacheEntity != null)
            {
                await RemoveItemAsync(cacheEntity, token);
            }
        }
Exemple #4
0
        public void RemoveItem(string key)
        {
            TableCacheEntity cacheEntity = RetrieveItem(key);

            if (cacheEntity != null)
            {
                RemoveItem(cacheEntity);
            }
        }
Exemple #5
0
        public async Task RefreshAsync(string key, CancellationToken token = default)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            TableCacheEntity cacheEntity = await _provider.RetrieveItemAsync(key, token);

            if (cacheEntity != null)
            {
                await RefreshEntityAsync(cacheEntity);
            }
        }
Exemple #6
0
        public void Refresh(string key)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            TableCacheEntity cacheEntity = _provider.RetrieveItem(key);

            if (cacheEntity != null)
            {
                RefreshEntity(cacheEntity);
            }
        }
Exemple #7
0
        private bool ShouldDelete(TableCacheEntity cacheEntity)
        {
            DateTimeOffset currentTime = DateTimeOffset.UtcNow;

            if (cacheEntity.AbsoluteExpiration.HasValue && cacheEntity.AbsoluteExpiration.Value <= currentTime)
            {
                return(true);
            }

            if (cacheEntity.SlidingExpiration.HasValue && cacheEntity.LastAccessedTime.HasValue &&
                cacheEntity.LastAccessedTime.Value.Add(cacheEntity.SlidingExpiration.Value) < currentTime)
            {
                return(true);
            }

            return(false);
        }
Exemple #8
0
        private TableCacheEntity RefreshEntity(TableCacheEntity cacheEntity)
        {
            if (cacheEntity is null)
            {
                return(null);
            }

            if (cacheEntity.Data is null || ShouldDelete(cacheEntity))
            {
                _provider.RemoveItem(cacheEntity);
                return(null);
            }

            cacheEntity.LastAccessedTime = DateTimeOffset.UtcNow;
            _provider.InsertOrUpdateItem(cacheEntity);
            return(cacheEntity);
        }
Exemple #9
0
        public async Task <byte[]> GetAsync(string key, CancellationToken token = default)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            TableCacheEntity cacheEntity = await _provider.RetrieveItemAsync(key, token);

            if (cacheEntity is null)
            {
                return(null);
            }

            await RefreshEntityAsync(cacheEntity);

            return(cacheEntity?.Data);
        }
Exemple #10
0
        public byte[] Get(string key)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            TableCacheEntity cacheEntity = _provider.RetrieveItem(key);

            if (cacheEntity is null)
            {
                return(null);
            }

            RefreshEntity(cacheEntity);

            return(cacheEntity.Data);
        }
Exemple #11
0
        private async Task <TableCacheEntity> RefreshEntityAsync(TableCacheEntity cacheEntity, CancellationToken token = default)
        {
            if (cacheEntity is null)
            {
                return(null);
            }

            if (cacheEntity.Data is null || ShouldDelete(cacheEntity))
            {
                await _provider.RemoveItemAsync(cacheEntity, token);

                return(null);
            }

            cacheEntity.LastAccessedTime = DateTimeOffset.UtcNow;
            await _provider.InsertOrUpdateItemAsync(cacheEntity, token);

            return(cacheEntity);
        }
Exemple #12
0
        public Task RemoveItemAsync(TableCacheEntity entity, CancellationToken token)
        {
            TableOperation operation = TableOperation.Delete(entity);

            return(_cloudTable.ExecuteAsync(operation));
        }
Exemple #13
0
        public void RemoveItem(TableCacheEntity entity)
        {
            TableOperation operation = TableOperation.Delete(entity);

            _cloudTable.Execute(operation);
        }
Exemple #14
0
        public Task InsertOrUpdateItemAsync(TableCacheEntity entity, CancellationToken token)
        {
            TableOperation operation = TableOperation.InsertOrReplace(entity);

            return(_cloudTable.ExecuteAsync(operation, token));
        }
Exemple #15
0
        public void InsertOrUpdateItem(TableCacheEntity entity)
        {
            TableOperation operation = TableOperation.InsertOrReplace(entity);

            _cloudTable.Execute(operation);
        }