什么是强迫缓存过期ASP.NET中的最好方法? [英] What's the best method for forcing cache expiration in ASP.NET?
问题描述
假设我有跨多个Web服务器上运行的负载平衡器后面的ASP.NET应用程序:
Suppose I have an ASP.NET application running across several web servers behind a load balancer:
我可以:
-
力的OutputCache(页和/或控制电平)在全球范围内过期?
Force OutputCache (Page and/or Control level) to expire globally?
力数据缓存(即Cache.Insert)到期?
Force Data Cache (i.e. Cache.Insert) to expire?
从一个中央位置监控ASP.NET缓存使用(键,RAM等)?
Monitor ASP.NET caching usage (keys, RAM, etc) from a central location?
一种可能的解决办法是有高速缓存的每次使用检查文件依赖更改。该文件可能被触及这将过期的所有高速缓存。然而,这要求开发人员在其所有code的依赖。是他们的一个更好的解决方案?
One possible solution would be to have every usage of cache check a file dependency for changes. The file could be touched which would expire all cache. However, this requires developers to include the dependency in all their code. Is their a better solution?
推荐答案
有许多方法可以使这些缓存过期,如页面的OutputCache通过
There are many ways to make these caching expire, like page outputcache by
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)
基于时间的依赖性仅仅在一个时间限定点过期的项目
Time-based dependency simply expires the item at a defined point in time.
Response.Cache.SetExpires(DateTime.Now.AddSeconds(360));
Response.Cache.SetCacheability(HttpCacheability.Private)
Response.Cache.SetSlidingExpiration(true);
现在,当涉及到监测缓存,除非上的缓存来告诉你一个API,那么有没有直接的方法。
Now when it comes to monitoring cache, unless there is an API on the cache to tell you, then there is no direct way.
您当然可以列举缓存,键 - 值对,然后计算存储每个项目的大小。犯规听起来很容易吧??
You could of course enumerate the cache,key-value pairs and then calculate the size of each item stored. Doesnt sound easy right??
的使缓存监控方便。坦白说,我从来没有使用过自己,但你可以试试看,增加一个dll到你的应用程序只是此事。
So here's to make your cache monitoring easy. Frankly saying i never used it myself, but you can give it a try, just the matter of adding a dll to your application.
和这里的东西为你的缓存键查看,
And here's something for your cache keys view,
' display contents of the ASP.NET Cache
If Cache.Count > 0 Then
cc.Append("<b>Contents of the ASP.NET Cache (" _
& Cache.Count.ToString() & " items):</b><br />")
For Each item As Object In Cache
cc.Append("Key:'" & item.Key & "' Type:" _
& item.Value.GetType().ToString() & "<br />")
Next
Else
cc.Append("<b>ASP.NET Cache is empty</b>")
End If
这篇关于什么是强迫缓存过期ASP.NET中的最好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!