简体   繁体   English

使用Socket.io在本地(在浏览器中)缓存数据?

[英]Caching data locally (in browser) received using Socket.io?

Is there a library/project which smooths over the process of caching some json data in the browser when using socket.io? 是否有一个库/项目可以简化使用socket.io时在浏览器中缓存某些json数据的过程? I guess what I really mean is , is there a github/opensource project already out there focused on this task so that a developer could more or less drop it into any socket.io project? 我想我的意思是 ,是否已经有一个专注于此任务的github / opensource项目,以便开发人员或多或少将其放入任何socket.io项目中?

For example, let's say I am getting tabular data for a page and the data is received by using socket.io. 例如,假设我正在获取页面的表格数据,并且该数据是通过使用socket.io接收的。 I want the data to remain cached so that I can save a server request if the user reloads the browser. 我希望数据保持高速缓存,以便在用户重新加载浏览器时可以保存服务器请求。

Additionally, I'd want this to happen more or less without me having to manually create cache variables, like: http://davidwalsh.name/cache-ajax . 另外,我希望这种情况或多或少会发生,而无需手动创建缓存变量,例如: http : //davidwalsh.name/cache-ajax I want the socket.io cache library to be able to do this for me. 我希望socket.io缓存库能够为我执行此操作。

I want to occasionally & easily be able to clear the cache if it changed on the server. 如果服务器上更改了缓存,我希望能够偶尔轻松地清除缓存。 So, let's assume for that what I'm looking for has a method for analyzing timestamps on when the remote data was modified. 因此,让我们假设我正在寻找一种可以分析远程数据何时被修改的时间戳的方法。 What I mean is, let's assume for now that there is a way of notifying the browser when database table/rows/documents have been modified so that it knows when to clear the socket.io cache (perhaps sending meta information about database table modify timestamps along with data requests or maybe with an occasional comet-type message). 我的意思是,让我们现在假设有一种方法可以在数据库表/行/文档被修改时通知浏览器,以便它知道何时清除socket.io缓存(也许发送有关数据库表修改时间戳的元信息)以及数据请求或偶尔出现的彗星型消息)。

Why not use local storage? 为什么不使用本地存储? Read about it from Mozilla Developer Network Mozilla开发人员网络中阅读

It is easier to use. 它更易于使用。

To set value 设定值

localStorage[ 'key' ] = strValue;

To retrieve 取回

strVal = localStorage[ 'key' ];

Yup, just simple associative arrays 是的,只是简单的关联数组

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

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