private void Add(string key, string value) { byte[] encodedValue = Encoding.UTF8.GetBytes(value); Cache[key] = new DistributeCacheModel { Key = key, Value = encodedValue, CreatedDate = DateTime.Now, SlidingExpirationInSecond = second }; _context.Add(Cache[key]); _context.SaveChanges(); }
private void Update(string key, string value) { var item = _context.DistributeCacheModels.Where(x => x.Key.ToLower().Contains(key.ToLower())).FirstOrDefault(); item.Value = Encoding.UTF8.GetBytes(value); _context.Update(item); _context.SaveChanges(); Cache[key] = new DistributeCacheModel { Key = key, Value = item.Value, CreatedDate = DateTime.Now, SlidingExpirationInSecond = second }; }