コード例 #1
0
        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 {
            }
        }
コード例 #2
0
        public bool Expired()
        {
            var expired = _loadStatus == CacheLoadStatus.Loaded &&
                          LoadedOn.AddSeconds(_settings.FullSetCacheExpirationSec) < _timeService.UtcNow;

            if (expired && _loadStatus == CacheLoadStatus.Loaded)
            {
                _loadStatus = CacheLoadStatus.NonCurrent;
            }
            return(expired);
        }
コード例 #3
0
 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;
 }
コード例 #4
0
        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();
        }
コード例 #5
0
 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();
         }
     }
 }