コード例 #1
0
        private bool IsExpired(CacheEntry entry)
        {
            if (this.ttl == null)
            {
                return false;
            }

            return (DateTimeOffset.UtcNow - entry.CreatedAt) > this.ttl.Value;
        }
コード例 #2
0
        Map ISynchronousCache.Put(string key, Map value)
        {
            try
            {
                var db = this.connection.GetDatabase();

                var cacheKey = this.ConstructKey(key);
                var cacheData = this.serializer.Serialize(value);

                var entry = new CacheEntry(
                    cacheData,
                    DateTimeOffset.UtcNow);

                db.StringSet(cacheKey, entry.ToString(), this.tti);
            }
            catch (Exception e)
            {
                this.logger.Error(e, "Error while storing value in cache.", "RedisSyncCache.Put");
            }

            return value;
        }
コード例 #3
0
#pragma warning restore CS4014

        async Task<Map> IAsynchronousCache.PutAsync(string key, Map value, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            try
            {
                var db = this.connection.GetDatabase();

                var cacheKey = this.ConstructKey(key);
                var cacheData = this.serializer.Serialize((Map)value);

                var entry = new CacheEntry(
                    cacheData,
                    DateTimeOffset.UtcNow);

                await db.StringSetAsync(cacheKey, entry.ToString(), this.tti).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                this.logger.Error(e, "Error while storing value in cache.", "RedisAsyncCache.PutAsync");
            }

            return value;
        }