체크 아웃
MVC http://bstavroulakis.com/blog/web/custom-output-caching-in-asp-net-mvc/ ASP.NET에서 사용자 정의 출력 캐시를 만드는 방법에 대한 내 블로그 게시물을 내가했다)
1
을 만난 능력을 가지고하지 않은 출력 캐시에서 다음 기대 필요한 경우 캐싱 객체를보고 필요한 모든 부분을 무효화하십시오.
2) 필요할 때 캐싱을 사용하지 않도록 설정할 수 있습니다.
3) 항목이 캐시 된 전후에 일부 논리가 있습니다.
4) 정적 사이트
5)뿐만 아니라 사이트의 다른 부분에서 캐시 구조를 사용의 나머지는 데, 사이트 및로드 부분 만 동적 일부 되세요.
내 행동 여기서
- 찾기/추가/제거 내 자신의 CacheManager/... 캐시에 객체를 생성합니다.그 후
public class CacheManager
{
#region ICacheManager Members
public static void Add(string key, object value, int expireSeconds)
{
if (expireSeconds == CacheManagerKey.CacheLifeSpanForever)
WebCache.Add(key, value, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
else
WebCache.Add(key, value, null, DateTime.MaxValue, TimeSpan.FromSeconds(expireSeconds), CacheItemPriority.Normal, null);
}
public static bool Contains(string key)
{
return WebCache.Get(key) != null;
}
public static int Count()
{
return WebCache.Count;
}
public static void Insert(string key, object value)
{
WebCache.Insert(key, value);
}
public static T Get(string key)
{
return (T)WebCache.Get(key);
}
public static List GetCacheKeys()
{
List keys = new List();
foreach (DictionaryEntry entry in HttpContext.Current.Cache) keys.Add(entry.Key.ToString());
return keys;
}
public static void Remove(string key)
{
WebCache.Remove(key);
}
public static void RemoveAll()
{
List keys = GetCacheKeys();
foreach (string key in keys)
WebCache.Remove(key);
}
public object this[string key]
{
get
{
return WebCache[key];
}
set
{
WebCache[key] = value;
}
}
#endregion
public static System.Web.Caching.Cache WebCache
{
get
{
System.Web.Caching.Cache cache = null;
if (HttpContext.Current != null)
cache = HttpContext.Current.Cache;
if (cache == null)
cache = HttpRuntime.Cache;
return cache;
}
}
}
은 내가 "Donut Caching"
마지막을 사용하는 일부 동적 가지고 내 자신의 속성
[AttributeUsage(AttributeTargets.All, Inherited = true, AllowMultiple = false)]
public class WebCacheAttribute : ActionFilterAttribute
{
public int Duration { get; set; }
public string CacheKey { get; set; }
public Dictionary CacheParams { get; set; }
public Type CacheReturnType { get; set; }
public string ContentType { get; set; }
public HeaderContentTypeEnum ResponseHeaderContentType{get;set;}
public string CacheObj { get; set; }
private readonly ICacheHoleFiller _cacheHoleFiller;
public WebCacheAttribute(int duration, string cacheKey, string cacheParamsStr, HeaderContentTypeEnum response = HeaderContentTypeEnum.Html, Type type = null)
{
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
}
public T GetCachedParam(Dictionary parameters, bool isAjaxRequest)
{
}
public string GetUniqueKey(bool isAjaxRequest)
{
}
public void OnException(ExceptionContext filterContext)
{
}
private HtmlTextWriter tw;
private StringWriter sw;
private StringBuilder sb;
private HttpWriter output;
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
}
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
}
}
var articleStr = CacheHelper.InvokeCacheMethod(typeof(HtmlHelperExtensions), "RenderArticlesCallback", new object[] { (int)articleType });
[WebCacheAttribute(CacheManagerKey.CacheLifeSpanForever, CacheManagerKey.Page_Article_Key, "articleTypeID")]
public static string RenderArticlesCallback(int articleTypeID)
{
public static class CacheHelper
{
public delegate object SourceDataDelegate(object[] args);
public static T InvokeCacheMethod(Type type, string methodName, object[] args)
{
return (T)InvokeCacheMethod(type, methodName, null, args);
}
public static T InvokeCacheMethod(Type type, string methodName, object instance, object[] args)
{
var method = type.GetMethod(methodName);
var webCache = method.ReturnParameter.Member.GetCustomAttributes(typeof(WebCacheAttribute), true).FirstOrDefault();
Dictionary cacheParameters = FixCacheParameters(method, args);
T cachedObj;
if (Config.CacheEnabled && webCache != null)
{
cachedObj = ((WebCacheAttribute)webCache).GetCachedParam(cacheParameters, false);
if (cachedObj != null)
return cachedObj;
}
T returnObj = (T)method.Invoke(instance, args);
SaveCachedData(webCache, returnObj);
return returnObj;
}
public static void SaveCachedData(object webCache, object returnObj)
{
if (Config.CacheEnabled && webCache != null)
{
var fullParamString = ((WebCacheAttribute)webCache).GetUniqueKey(false);
CacheManager.Add(fullParamString, returnObj, ((WebCacheAttribute)webCache).Duration);
}
}
public static Dictionary FixCacheParameters(MethodInfo method, object[] args)
{
Dictionary cacheParameters = new Dictionary();
if (args != null)
{
var arguments = args.ToList();
var count = 0;
var argsCount = args.Length;
var methodParameters = method.GetParameters().ToList();
foreach (var argument in args)
{
var key = methodParameters[count].Name;
object value = null;
if (argsCount > count)
value = args[count];
if (value != null && value.GetType() == typeof(string))
value = (object)value.ToString();
if (value != null)
cacheParameters.Add(key, value);
count++;
}
}
return cacheParameters;
}
}
후 =>
Custom Output Caching in ASP.NET MVC은 어쩌면 당신은 캐시에서 추가로 들어있는 항목을 제거하려고 매개 변수는 live = true이고, live가없는 것은 아닙니다. 캐시에서 제거하기 전에 "urlToRemove"값이 올바른지 확인하십시오. –
urlToRemove 속성을 살펴 보았지만 "라이브"매개 변수가 없습니다. 라이브 패러미터가없는 Action 매개 변수에서 URL을 작성하기 때문에 기대할 수있는 것은 무엇입니까. –