示例#1
0
        /// <see cref="INodeMappingEngine.SetCacheProvider"/>
        public void SetCacheProvider(ICacheProvider cacheProvider)
        {
            if (_cacheProvider != null)
            {
                _cacheProvider.Clear();

                content.AfterUpdateDocumentCache -= _documentCacheEventHandler;
                content.AfterClearDocumentCache  -= _documentCacheEventHandler;

                _documentCacheEventHandler = null;
            }

            if (cacheProvider != null)
            {
                _documentCacheEventHandler = (sender, e) => cacheProvider.Clear();

                // TODO test this

                content.AfterUpdateDocumentCache += _documentCacheEventHandler;
                content.AfterClearDocumentCache  += _documentCacheEventHandler;

                // TODO Support the below for custom mappings which use the cache, you never know
                //Media.AfterSave += _documentCacheEventHandler;
                //Media.AfterDelete += _documentCacheEventHandler;
                //CMSNode.AfterMove += _documentCacheEventHandler;
                //Member.AfterSave += _documentCacheEventHandler;
                //Member.AfterDelete += _documentCacheEventHandler;
            }

            _cacheProvider = cacheProvider;
        }
        public async Task <IActionResult> FlushCache()
        {
            Request.Headers.TryGetValue("X-Signature", out StringValues signature);

            using (var reader = new StreamReader(Request.Body))
            {
                var requestBody = await reader.ReadToEndAsync();

                var generatedSignature = $"{requestBody}{_secret}".Sha256Base64();

                if (generatedSignature == signature)
                {
                    try
                    {
                        dynamic jObject = JObject.Parse(requestBody);
                        var     payload = jObject.payload;

                        string schemaName = ((string)payload.schemaId).Split(',')[1];
                        string contentID  = payload.contentId;

                        //clear from cache
                        _cacheProvider.Clear(schemaName);
                        _cacheProvider.Clear(contentID);

                        return(Ok());
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, "An error ocurred trying to flush cached items");
                    }
                }
            }
            _logger.LogError("Could not authenticate request");
            return(Unauthorized());
        }
示例#3
0
 /// <summary>
 /// Creates an item of type T in the repository and then flushes the cache
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public bool Create(T t)
 {
     // Create the item and refresh the cache. Cache wil be updated on next fetch
     if (!_repository.Create(t))
     {
         throw new Exception("Could not create item");
     }
     _cacheProvider.Clear();
     return(true);
 }
 public static void ClearAll(this ICacheProvider cacheProvider)
 {
     if (cacheProvider != null)
     {
         cacheProvider.Clear();
     }
 }
示例#5
0
        public async Task <IHttpActionResult> SavePreferences(UserPreferencesModel model)
        {
            var entity = await _db.UserPreferences.FindAsync(User.Identity.GetUserId()) ?? new AppUserPreferences();

            entity.Id = User.Identity.GetUserId();
            entity.ChartPreferences = new ChartPreferences
            {
                LegendShowen   = model.ChartPreferences.ShowLegend,
                XLineVisible   = model.ChartPreferences.XLineVisible,
                YLineVisible   = model.ChartPreferences.YLineVisible,
                PointSize      = model.ChartPreferences.PointSize,
                FontSize       = model.ChartPreferences.FontSize,
                FontFamilyName = model.ChartPreferences.FontFamilyName,
                PaletteColors  = model.ChartPreferences.PaletteColors.Select(item => item.Color).ToArray()
            };

            if (_db.Entry(entity).State == EntityState.Detached)
            {
                _db.UserPreferences.Add(entity);
            }

            await _db.SaveChangesAsync();

            _cacheProvider.Clear();
            return(Ok());
        }
示例#6
0
 public void PurgeCache()
 {
     //clear the provider cache
     _cacheProvider.Clear();
     //clear the view cache
     ReadFile.PurgeCache();
     //clear the active theme template cache
     _themeProvider.ResetActiveTheme();
     //clear view location caches
     _viewAccountant.ClearCachedViews();
 }
示例#7
0
        public virtual void ClearTest()
        {
            string node1  = "/ClearTest1";
            string value1 = "ClearTestValue1";
            string node2  = "/ClearTest1/Inner";
            string value2 = "ClearTestValue2";

            cacheProvider.Add(node1, value1).Wait();
            cacheProvider.Add(node2, value2).Wait();
            cacheProvider.Get <string>(node1).ShouldBe(value1);
            cacheProvider.Get <string>(node2).ShouldBe(value2);
            cacheProvider.Clear(node1).Wait();
            //回调是异步的不能保证已经执行完成,这里用Sleep进行一定的模拟
            Thread.Sleep(5000);
            cacheProvider.Get <string>(node1).ShouldBeNull();
            cacheProvider.Get <string>(node2).ShouldBeNull();
        }
示例#8
0
 public void ClearAll()
 {
     _cache.Clear(typeof(AggregateRegister).FullName);
 }
示例#9
0
 public void Clear()
 {
     cacheProvider.Clear();
 }
示例#10
0
 public void Clear()
 {
     _localCacheProvider.Clear();
 }
示例#11
0
 public void ClearAll()
 {
     _cache.Clear();
 }
示例#12
0
 public Task Clear()
 {
     provider.Clear();
     return(Task.FromResult((object)null));
 }
示例#13
0
 /// <summary> 清空缓存
 /// </summary>
 public void Clear()
 {
     provider.Clear();
 }
示例#14
0
 public ActionResult Clear()
 {
     return(Ok(_cacheProvider.Clear()));
 }
 public IHttpActionResult Get()
 {
     _cacheProvider.Clear();
     return(Ok("Cache cleared successfully."));
 }
        public void GetSystemConfiguration_when_cache_provider_is_not_null_and_cache_value_is_not_null_return_cache_value()
        {
            //arrange
            var sysconfig = new SystemConfigurationObject()
            {
                SettingId = 2
            };

            _fakecacheprovider.Set("GetSystemConfigurations", sysconfig);
            var mut = new SystemConfigurationService(_repository, _fakecacheprovider);
            //act
            var result = mut.GetSystemConfigurations();

            //assert
            Assert.AreEqual(sysconfig, result);
            //cleanup
            _fakecacheprovider.Clear("GetSystemConfigurations");
        }