public Authentication(string path) { //set up cache _cache = FileCacheHelper.GetGlobalCacheInstance(); _cache.DefaultRegion = "AuthenticationService"; //have our cache kill things after 2 days _cache.DefaultPolicy = new CacheItemPolicy { SlidingExpiration = new TimeSpan(2, 0, 0, 0, 0) }; }
private void SetUpCache() { _cache = FileCacheHelper.GetGlobalCacheInstance(); _cache.DefaultRegion = "AuthenticationService"; //have our cache kill things after 30 minutes _cache.DefaultPolicy = new CacheItemPolicy() { SlidingExpiration = new TimeSpan(0, 0, 30, 0, 0) }; }
public ControllerBase() { //set up DB Db = OsbideContext.DefaultWebConnection; //set up current user Authentication auth = new Authentication(); string authKey = auth.GetAuthenticationKey(); int id = auth.GetActiveUserId(authKey); //make sure that we got back a good key if (id > 0) { CurrentUser = Db.Users.Find(id); if (CurrentUser != null) { CurrentUser.PropertyChanged += CurrentUser_PropertyChanged; } else { CurrentUser = new OsbideUser(); } } else { CurrentUser = new OsbideUser(); } //set up caches GlobalCache = FileCacheHelper.GetGlobalCacheInstance(); UserCache = FileCacheHelper.GetCacheInstance(CurrentUser); //update all users scores if necessary object lastScoreUpdate = GlobalCache["lastScoreUpdate"]; bool needsScoreUpdate = true; if (lastScoreUpdate != null) { DateTime lastUpdate = (DateTime)lastScoreUpdate; if (lastUpdate.AddDays(1) > DateTime.UtcNow) { needsScoreUpdate = false; } } if (needsScoreUpdate == true) { //UpdateUserScores(); GlobalCache["lastScoreUpdate"] = DateTime.UtcNow; } //make current user available to all views ViewBag.CurrentUser = CurrentUser; }