Rails 如何知道何时从 `sessions` 表中删除记录? [英] How does Rails know when to delete a record from the `sessions` table?

查看:31
本文介绍了Rails 如何知道何时从 `sessions` 表中删除记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails 如何知道何时从会话表中删除记录?

How does Rails know when to delete a record from the sessions table?

比如,如果用户访问网站,会创建一个会话记录,但是当用户关闭浏览器窗口时,服务器没有收到任何通知,那么Rails如何从会话表中删除记录?

For example, if a user visits the website, a session record is created, but when the user closes the browser window, the server doesn't get any notification, so how does Rails delete records from sessions table?

推荐答案

据我所知,您必须提供自己的会话过期实现.

You have to provide your own implementation of session expiration, to my understanding.

这个 API 页面为您提供了一个相当不错的答案,说明它是如何工作的.您使用额外的属性 created_on 和 updated_at 创建您的数据库表(并且您可以免费获得时间戳),然后您只需创建一个作业,通过查看 updated_at 属性来随时使它们过期.

This API page gives you a pretty decent answer to how that works. You create your database table with the extra attributes created_on and updated_at (and you get timestamps for free) and then you just create a job to expire them whenever you want by looking at the updated_at attribute.

这篇博文详细介绍了如何运行作业.

This post has details of how to run a job.

这篇关于Rails 如何知道何时从 `sessions` 表中删除记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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