本文整理汇总了C#中ICacheService.Evict方法的典型用法代码示例。如果您正苦于以下问题:C# ICacheService.Evict方法的具体用法?C# ICacheService.Evict怎么用?C# ICacheService.Evict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICacheService
的用法示例。
在下文中一共展示了ICacheService.Evict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CacheSettingsPartHandler
public CacheSettingsPartHandler(
IRepository<CacheSettingsPartRecord> repository,
IWorkContextAccessor workContextAccessor,
ICacheService cacheService,
RequestContext requestContext)
{
_workContextAccessor = workContextAccessor;
_cacheService = cacheService;
_requestContext = requestContext;
Filters.Add(new ActivatingFilter<CacheSettingsPart>("Site"));
Filters.Add(StorageFilter.For(repository));
// initializing default cache settings values
OnInitializing<CacheSettingsPart>((context, part) => { part.DefaultCacheDuration = 300; });
// evict modified routable content when updated
OnPublished<IContent>(
(context, part) => {
// list of cache keys to evict
var evict = new List<CacheItem>();
var workContext = _workContextAccessor.GetContext();
Action<IContent> findAndEvict = p => {
foreach (var cacheItem in _cacheService.GetCacheItems()) {
var urlHelper = new UrlHelper(_requestContext);
if (String.Equals(cacheItem.Url, VirtualPathUtility.ToAbsolute("~/" + urlHelper.ItemDisplayUrl(p)), StringComparison.OrdinalIgnoreCase)) {
evict.Add(cacheItem);
}
}
};
findAndEvict(part);
// search the cache for containers too
var commonPart = part.As<CommonPart>();
if (commonPart != null) {
if (commonPart.Container != null) {
findAndEvict(commonPart.Container);
}
}
// remove all content to evict
foreach (var cacheItem in evict) {
_cacheService.Evict(cacheItem.CacheKey, workContext.HttpContext);
}
});
}