[英]How can I make my ActiveRecord objects only exist for 5 minutes in Ruby on Rails?
I've created a model called Request, which is created when one user makes a request with another user. 我已经创建了一个称为请求的模型,该模型是在一个用户向另一用户发出请求时创建的。 I'd like each request to only exist for 5 minutes.
我希望每个请求仅存在5分钟。 Is this possible?
这可能吗?
Couple of ways to do this ... you could add a Sweeper or delayed job to clear the values from the database periodically. 有几种方法可以执行此操作...您可以添加清除程序或延迟的作业以定期从数据库中清除值。 Give each record a created_at, clear after 5 minutes.
给每条记录一个created_at,5分钟后清除。
Alternative would be to do this check when presenting the information to the user ... similar idea, have a created_at, when you check the pending requests for the current user you ignore or delete any that are older than 5 minutes. 替代方法是在向用户提供信息时执行此检查...类似的想法,创建一个at_at,当您检查当前用户的待处理请求时,您会忽略或删除任何早于5分钟的请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.