重构代码:调用Longbow.V4组件内的清理缓存方法CacheListSection.ClearCache(cacheKeys)

This commit is contained in:
Argo-Lenovo 2017-04-06 12:12:17 +08:00
parent 6525a8f588
commit a4e97ce5cb
1 changed files with 2 additions and 25 deletions

View File

@ -1,11 +1,9 @@
using Bootstrap.Security; using Bootstrap.Security;
using Longbow.Caching; using Longbow.Caching;
using Longbow.Caching.Configuration; using Longbow.Caching.Configuration;
using Longbow.ExceptionManagement;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
namespace Bootstrap.DataAccess namespace Bootstrap.DataAccess
{ {
@ -81,29 +79,8 @@ namespace Bootstrap.DataAccess
cacheKeys.Add(ExceptionHelper.RetrieveExceptionsDataKey + "*"); cacheKeys.Add(ExceptionHelper.RetrieveExceptionsDataKey + "*");
} }
cacheKeys.AsParallel().ForAll(key => CacheManager.Clear(k => key.EndsWith("*") ? k.Contains(key.TrimEnd('*')) : k.Equals(key))); CacheManager.Clear(k => cacheKeys.Any(key => key.EndsWith("*") ? k.Contains(key.TrimEnd('*')) : key == k));
System.Threading.Tasks.Task.Factory.StartNew(() => CacheListSection.ClearCache(cacheKeys);
{
var section = CacheListSection.GetSection();
section.Items.Where(item => item.Enabled).Skip(1).AsParallel().ForAll(ele =>
{
try
{
using (var client = new WebClient())
{
cacheKeys.ForEach(k => client.OpenRead(string.Format(ele.Url, k)));
}
}
catch (Exception ex)
{
System.Collections.Specialized.NameValueCollection nv = new System.Collections.Specialized.NameValueCollection();
nv["ErrorPage"] = ele.Url;
nv["UserId"] = "system";
nv["UserIp"] = "::1";
ExceptionManager.Publish(ex, nv);
}
});
});
} }
} }
} }