简体   繁体   English

注销后如何清除浏览器缓存(内存/磁盘缓存)?

[英]How can I clear browser cache (memory / disk cache) after logout?

I use asp.net core mvc + js.我用的是asp.net核心mvc+js。 One type of my pages have cache.我的一种页面有缓存。

[ResponseCache(Location = ResponseCacheLocation.Client, Duration = 60)]
public async Task<IActionResult> StaticContent(string path)
{
    // code
}

I have a problem when user logout on this page.用户在此页面上注销时出现问题。 User sees his account after logout because page was cache.用户在注销后看到他的帐户,因为页面被缓存。 If refresh page cache clear and user does not see account.如果刷新页面缓存清除并且用户看不到帐户。

I try location.reload();我尝试location.reload(); on js when logout click but reload work earlier than logout work on server.在 js 上注销时单击但重新加载工作早于服务器上的注销工作。 I try change Vary header but I change Vary only page which I redirect after logout我尝试更改 Vary header 但我仅更改了 Vary 页面,我在注销后重定向了该页面

How can I clear cache after logout?注销后如何清除缓存? Any ideas?有任何想法吗?

As the King King says, if you enable the client cache, there is no way to tell the client side in the server-side.正如King King所说,如果启用客户端缓存,则无法在服务器端告诉客户端。 The only way is just tell the CX to clear the cache.唯一的方法就是告诉 CX 清除缓存。 Since once the browser obeys the cache rules you send here, the only opportunity you will have to retract your cache rules is the next time the browser requests the page.由于一旦浏览器遵守您在此处发送的缓存规则,您将不得不撤回缓存规则的唯一机会是浏览器下一次请求该页面时。

Normally, the dynamic pages should not attempt to set client-side caching if you want them to stay dynamic.通常,如果您希望动态页面保持动态,则不应尝试设置客户端缓存。

I find answer on microsoft site https://docs.microsoft.com/en-us/aspnet/core/performance/caching/response?view=aspnetcore-5.0#responsecache-attribute They say don`t cache content which using user info.我在微软网站https://docs.microsoft.com/en-us/aspnet/core/performance/caching/response?view=aspnetcore-5.0#responsecache-attribute他们说不要缓存使用用户信息的内容.

I cache individual parts of page without account info.我在没有帐户信息的情况下缓存页面的各个部分。 I use我用

<cache expires-after="" />

Thanks all谢谢大家

In your logout post, you can clear a session that may solve your problem.在您的注销帖子中,您可以清除 session,这可能会解决您的问题。

HttpContext.Session.Clear(); //this will clear all session 
HttpContext.Session.Remove("sessionName"); //this will clear a specific session

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM