public void SetValue(string key, string value) { lock (SyncRoot) { using (var dbContext = new SocialExperimentDbContext()) { var setting = dbContext.Settings.SingleOrDefault(a => a.Key == key); if (setting == null) { setting = new Setting(); setting.Key = key; setting.Value = string.Empty; dbContext.Settings.Add(setting); } setting.Value = value; dbContext.SaveChanges(); } var cacheKey = GetCacheKey(key); MemoryCache.Default.Set(cacheKey, value, ObjectCache.InfiniteAbsoluteExpiration); } }
public string GetValue(string key) { var cacheKey = GetCacheKey(key); var value = (string) MemoryCache.Default.Get(cacheKey); if (value != null) { return value; } lock (SyncRoot) { value = (string) MemoryCache.Default.Get(cacheKey); if (value != null) { return value; } Setting setting; using (var dbContext = new SocialExperimentDbContext()) { setting = dbContext.Settings.SingleOrDefault(a => a.Key == key); } if (setting == null) { return null; } value = setting.Value; MemoryCache.Default.Set(cacheKey, value, ObjectCache.InfiniteAbsoluteExpiration); } return value; }
public PlacesContext() { this.dbContext = new SocialExperimentDbContext(); Mapper.CreateMap<CountryEntity, CountryDto>(); }