流星会议 [英] Sessions in Meteor

查看:67
本文介绍了流星会议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过研究,似乎 Meteor 会话在刷新页面或在新选项卡中打开网站后重置,即它们不是通常的服务器端会话,而是类似于客户端的全局 javascript 变量.有些人建议使用 AmplifyJS,但我不确定它是否会像其他框架/语言中的常规会话一样工作,而且它是第三方库,所以在 Meteor 中使用会话有什么正常的方法,即保持用户-服务器上的具体数据?

After a research it seems that Meteor Sessions are reset after refreshing page or opening the website in new tab, i.e. they are not usual server-side sessions but something like global javascript variables on client-side. Some people advice to use AmplifyJS, but I'm not sure that it will work like usual session in other frameworks/languages and also it is a third party library, so is there any normal way to use sessions in Meteor, i.e. keep user-specific data on server?

目前我正在通过使用自定义集合来处理这个问题,但这不是一种理想的方法,因为需要手动从集合中删除过期值,这会带来额外的麻烦.

At this moment I'm handling that by using custom Collections, but it is not an ideal way of doing that because it is needed to remove expired values from Collection manually, which makes additional troubles.

推荐答案

是的,这是正确的.尽管名称 Session 与 cookie 完全不同,但它只是存储在哈希映射中的变量的反应形式

Yes this is correct. Despite the name Session is nothing like a cookie, but just a reactive form of a variable stored in a hashmap

要使数据跨选项卡保持持久性,您需要使用集合(因为这是跨选项卡被动共享数据的唯一方法)- Cookie 无法工作,因为它们无法响应,因为需要将数据发送到服务器在发生变化时通知客户端.目前确实没有其他方法,因为发布/订阅方法目前只能从集合中发送数据.

To keep data persistent across tabs you need to use a Collections (as this is the only way to reactively share data across tabs) - Cookies can't work because they can't be made reactive as data needs to be sent to the server to notify the client when there is a change. There really wouldn't be another way at the moment as the publish/subscribe methods can only send down data from collections at the moment.

您可以将您现在的设置与您的自定义集合一起使用.您可以使用服务器端 cron 作业删除过期数据(使用 Meteor.setIntervalTom Coleman 的 cron.

You can use your setup you have now with your custom collection. You can use a server side cron job to remove expired data (either with Meteor.setInterval or Tom Coleman's cron.

这篇关于流星会议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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