当且仅当在浏览器端清除缓存时,如何清除服务器端的缓存? [英] How do I clear cache memory on the server side when and only when cache is cleared on the browser side?

查看:202
本文介绍了当且仅当在浏览器端清除缓存时,如何清除服务器端的缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在键中存储了一个值并将其缓存(使用HttpRunTime.Cache.Insert)一段特定的时间(比如20分钟)。现在,我想在从用户浏览器中清除缓存时清除缓存。我该怎么做(我需要在服务器端编写哪些代码)?



我尝试了什么:



我尝试过HttpRunTime.Cache缓存和HttpContext.Current.Caching但缓存只在超时提供的时间后清除,而不是在用户清除浏览器时清除缓存。请建议我替代,因为我是ASP.Net缓存的新手

解决方案

服务器不知道用户何时清除缓存,因此您无法做出反应它。您可能需要做一些事情,例如在每个页面上放置一个处理程序的链接,并让它处理If-Modified-Since标题。如果该标头为空,那么这是用户第一次请求该URL,因此您可以假设它是第一次命中,或者他们已清除其缓存,并在该点清除服务器端数据(如果存在)。 / BLOCKQUOTE>

I have stored a value in a key and cached it(using HttpRunTime.Cache.Insert) for a specific period of time(say 20 mins). Now I want to clear the cache whenever the cache is cleared from the browser the user. How do I do it(what code do I need to write on the server side for that)?

What I have tried:

I have tried HttpRunTime.Cache caching and HttpContext.Current.Caching but the cache only gets cleared after the amount of time provided in time out and not when user clears the browser cache. Please suggest me an alternate as I am new to ASP.Net caching

解决方案

The server doesn't know when the user clears their cache so you can't react to it. You might have to do something like put a link to a handler on every page, and have it process the "If-Modified-Since" header. If that header is empty then this is the first time the user has requested the url so you could assume it is their first hit, or that they have cleared their cache, and clear the server-side data at that point if it exists.


这篇关于当且仅当在浏览器端清除缓存时,如何清除服务器端的缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆