public void Reload(object reason) { _loadStatus = CacheLoadStatus.Loading; if (_app.Status != EntityAppStatus.Connected) //stop if we're in shutdown { return; } var session = (EntitySession)this.OpContext.OpenSystemSession(); try { session.LogMessage("------- Full-set cache - reloading/" + reason); var entSets = new Dictionary <Type, FullyCachedSet>(); foreach (var entType in _settings.FullSetCacheTypes) { if (_loadStatus != CacheLoadStatus.Loading) { session.LogMessage("------- Full-set cache - reload canceled."); return; // stop if another cache invalidation request came in } var entInfo = _app.Model.GetEntityInfo(entType); var cmd = entInfo.CrudCommands.SelectAll; var records = _dataStore.ExecuteSelect(session, cmd, null); var entSet = new FullyCachedSet(entInfo, records); entSets.Add(entType, entSet); } this.EntitySets = entSets; LoadedOn = _timeService.UtcNow; _loadStatus = CacheLoadStatus.Loaded; session.LogMessage("------- Full-set cache - reloaded."); } catch (Exception ex) { _loadStatus = CacheLoadStatus.NonCurrent; _errorLog.LogError(ex, this.OpContext); } finally { } }
public bool Expired() { var expired = _loadStatus == CacheLoadStatus.Loaded && LoadedOn.AddSeconds(_settings.FullSetCacheExpirationSec) < _timeService.UtcNow; if (expired && _loadStatus == CacheLoadStatus.Loaded) { _loadStatus = CacheLoadStatus.NonCurrent; } return(expired); }
public FullSetEntityCache(EntityApp app, CacheSettings settings, IDataStore dataStore, StringCaseMode caseMode) { _app = app; _settings = settings; _dataStore = dataStore; _caseMode = caseMode; _queryCache = new ObjectCache <string, EntityCacheQuery> (expirationSeconds: 5 * 60, maxLifeSeconds: 10 * 60); _timeService = _app.GetService <ITimeService>(); _errorLog = _app.GetService <IErrorLogService>(); OpContext = new OperationContext(_app, UserInfo.System); CurrentVersion = 0; _loadStatus = CacheLoadStatus.NonCurrent; }
public void ReloadAsync(string reason) { if (_app.Status != EntityAppStatus.Connected) { return; } if (!_app.CacheSettings.CacheEnabled) { return; } _loadStatus = CacheLoadStatus.Loading; var task = new System.Threading.Tasks.Task(Reload, reason); task.Start(); }
public void Invalidate(bool reload = false, bool waitForReloadComplete = false) { _loadStatus = CacheLoadStatus.NonCurrent; if (OpContext.LocalLog != null) { OpContext.LocalLog.Info("---- Full-set cache invalidated."); } // _maxKnownVersion++; if (reload) { ReloadAsync("invalidate"); } if (waitForReloadComplete) { var endBefore = _timeService.UtcNow.AddSeconds(5); while (_loadStatus != CacheLoadStatus.Loaded && _timeService.UtcNow < endBefore) { Thread.Yield(); } } }