private string Get(string key) { try { if (_cache.TryGetValue(key, out Option option)) { return(option.Value); } else { option = _db.Options.AsNoTracking().Where(o => o.Id == key).FirstOrDefault(); if (option != null) { _cache.Add(key, option); return(option.Value); } else { return(null); } } } catch { _cache.Remove(key); return(null); } }
private void ClearPropertyCache(int?id = null) { _cache.Remove("Property:Featured"); _cache.Remove("Property:Recent"); if (id.HasValue) { _cache.Remove("Property:Listing:" + id.ToString()); } }
public async Task DeleteAllAsync(string type) { _db.Content.Where(c => c.ContentType == type).ForEach(p => { _db.Entry(p).State = EntityState.Deleted; string cacheKey = typeof(Content).ToString() + ".Single." + p.Id; _cache.Remove(cacheKey); }); await _db.SaveChangesAsync(); _eventService.TriggerContentChanged(this); }