Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

redis cache repository .net

namespace RedisHeroes.Core.Services
{
    public class CacheService : ICacheService
    {
        private readonly IDistributedCache _cache;

        public CacheService(IDistributedCache cache)
        {
            _cache = cache;
        }

        public T Get<T>(string key)
        {
            var value = _cache.GetString(key);

            if (value != null)
            {
                return JsonConvert.DeserializeObject<T>(value);
            }

            return default;
        }

        public T Set<T>(string key, T value)
        {
            var options = new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1),
                SlidingExpiration = TimeSpan.FromMinutes(10)
            };

            _cache.SetString(key, JsonConvert.SerializeObject(value), options);
            
            return value;
        }
    }
}
Comment

redis cache repository .net

namespace RedisHeroes.Core.Services
{
    public class CacheService : ICacheService
    {
        private readonly IDistributedCache _cache;

        public CacheService(IDistributedCache cache)
        {
            _cache = cache;
        }

        public T Get<T>(string key)
        {
            var value = _cache.GetString(key);

            if (value != null)
            {
                return JsonConvert.DeserializeObject<T>(value);
            }

            return default;
        }

        public T Set<T>(string key, T value)
        {
            var options = new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1),
                SlidingExpiration = TimeSpan.FromMinutes(10)
            };

            _cache.SetString(key, JsonConvert.SerializeObject(value), options);
            
            return value;
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: flat view player movement script 
Csharp :: int model property shows 0 in textbox .net core 
Csharp :: how to exit winforms application and shutdown pc in c# 
Csharp :: declarar lista c# 
Csharp :: devexpress spreadsheet document source wpf 
Csharp :: c# selenium xunit testing 
Csharp :: how to check if a file is running in c# 
Csharp :: c# integer part of float 
Csharp :: Send Hotmail, Outlook, Office365 Email using SMTP C# .NET 
Csharp :: web client ignore ssl error 
Csharp :: Lambda Expression to filter a list of list of items 
Csharp :: how to call an If statement only once in C# 
Csharp :: discord embeds how to separate inline fields 
Csharp :: unity sprite disappears when using transform.lookat 
Csharp :: mvc model validation for decimal type 
Csharp :: w3develops 
Csharp :: c# listview add items horizontally 
Csharp :: c# response.contenttype set filename 
Csharp :: vb.net drag window without titlebar 
Csharp :: subtract to time c# 
Csharp :: SQLite Parameters 
Csharp :: create class for database connection in c# 
Csharp :: how to move mouse with c# 
Csharp :: c# switch example 
Csharp :: change a positive number to negative or a negative number to positive 
Csharp :: how to remove from list from index c# 
Csharp :: while loop in c# 
Csharp :: This page contains six pages, created with MigraDoc and scaled down to fit on one page 
Csharp :: if session is not active then redirect to login page mvc.net 
Csharp :: C# Datagridview Column Header Double Click 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =