简体   繁体   English

如何使用JavaScript捕获缓存清除事件?

[英]how to catch cache clear event using javascript?

I am working on a socket based chat project. 我正在基于套接字的聊天项目。 I am storing all online users' name in database so that it can be checked for duplicate user name. 我将所有在线用户的名称存储在数据库中,以便可以检查是否有重复的用户名。 My application makes user offline easily if we are chatting and we directly close our browser but the problem is that when we directly clear cache memory at that time that AJAX call for deleting user from database will not be called. 我的应用程序使我们在聊天时可以轻松使用户脱机,并且我们直接关闭浏览器,但是问题是,当我们当时直接清除缓存时,将不会调用从数据库中删除用户的AJAX调用。 So even if we have cleared the cache and became offline, we are displayed online to the front user meaning that the entry still persist in data base because no AJAX call was fired and we had directly cleared cache. 因此,即使我们已经清除了缓存并变为脱机状态,也会在线显示给前端用户,这意味着该条目仍然存在于数据库中,因为没有触发AJAX调用并且我们直接清除了缓存。

So, anybody who has some idea regarding how to catch cache clear event using javascript , please let me know. 因此,任何对使用javascript捕获缓存清除事件有想法的人,请告诉我。

I have done a lot of googling on this issue but nothing found. 我已经在这个问题上进行了很多搜索,但没有发现。

Any suggestion will be entertained. 任何建议将被接受。

Thnx in advance..... 提前thnx .....

What you are asking for is impossible (there is no way to detect when the user clears their browser cache from JavaScript). 您所要求的是不可能的(无法检测用户何时从JavaScript清除浏览器缓存)。

Have you considered sending an invisible "ping" between both users every so often (pick a threshold like 1 minute), and for both users if they don't receive a ping for (threshold + smaller threshold), will consider the other user to be offline (or more robustly send a request for another "I am still here" ping). 您是否考虑过经常在两个用户之间发送不可见的“ ping”(选择一个阈值,如1分钟),对于两个用户,如果他们没有收到ping(阈值+较小阈值),将考虑另一个用户处于离线状态(或更可靠地发送另一个“我还在这里” ping请求)。

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

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