问题
Since the database-driven content of my site's home page changes infrequently, I use ASP.Net output caching to keep the content around for 1 hour:
<%@ OutputCache Duration="3600" VaryByParam="none" %>
I have a simple HTML comment at the beginning and end of the .ASCX control that I can use to verify that the output is being cached properly (by using 'view source' from within a browser):
<!-- Cached Area (Created at: 10:08:08 PM) Begin Cache -->
...
<!-- End Cached Area -->
The caching itself works great.
However, about once every day or so, ASP.NET captures an EMPTY cached area. As far as I can tell, this is because a robot (or other automated process) is the first thing to stop by the site when the previous cache is invalidated, and due to strange requests from the 'bot, the site creates an empty output... and then caches it.
Of course, this 'blank' section of the site is then seen by humans for the next hour, too.
Is there a way to "query" the output cache to see what's in it? Or (even better), to examine the "proposed" cache to and decide if it's sponge-worthy... err, I mean cache worthy?
I want to instantly dump (or never cache) the output if it doesn't contain the goods.
Note: examining the incoming request for validity is not a good solution, as there could have been a complex series of interactions before the output cache occurs. I need to be able to query the cache itself.
来源:https://stackoverflow.com/questions/4362980/asp-net-invalid-page-caching