令牌/激活表还是 Memcache?

发布于 2024-09-04 11:34:40 字数 245 浏览 10 评论 0原文

我最近发现的内存缓存引发了一股热潮,并为一切带来了新的可能性。

现在,当有人注册了我们的一项服务时,当我发送确认电子邮件时,我会在“令牌”表中创建“令牌”,该表有一个设定的有效期(通常为 3 天),供他们验证其帐户。

然后,我每天执行一次 cron 作业,查看是否有任何逾期的内容,在这种情况下,它会删除令牌。

这是可以用 memcache 来完成的事情吗?也许是一个更好的问题——这是应该用 memcache 来完成的事情吗?

My recent discovery of memcache has kind of created a craze and opening up everything to new possibilities.

Right now, when I send out a confirmation email when someone has signed up for one of our services, I create "token" in a "tokens" table that has a set expiration (usually 3 days) for them to verify their account.

I then have a daily cron job go through and see if anything is past due, in which case it deletes the token.

Is this something that could be done with memcache? Perhaps a better question -- is this something that should be done with memcache?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似狗非友 2024-09-11 11:34:40

应该?不会。Memcache 是一种瞬态内存缓存,这意味着它保存的任何数据都可能随时消失,或者至少您应该在这种假设下工作。即使内存缓存中根本没有存储任何内容,您的应用程序也应该功能齐全。事实上,一种相当常见的测试技术是创建一个虚拟内存缓存,该缓存中根本不存储任何数据。 (它具有存储和检索数据的方法,但它们不执行任何操作)一旦您对应用程序与虚拟缓存的配合感到满意,就可以将其交换出来并放入真正的内存缓存中。

实际上,它可能在大多数情况下都有效,因为除非您的计算机崩溃或内存不足,否则内存缓存不会因为感觉像这样而任意删除内容。但我认为使用内存缓存来做这样的事情是不好的做法。

Should? No. Memcache is a transient memory cache, which means that any data it holds could disappear at any moment, or at least you should work under that assumption. Your app should be fully functional even if nothing gets stored in memcache at all. In fact, a reasonably common testing technique is to create a dummy memory cache that doesn't store any data in the cache at all. (It has the methods to store and retrieve data, but they don't do anything) Once you're satisfied your app works with the dummy cache, then you swap it out and put in the real memcache.

In practice, it would probably work most of the time, since unless your computer crashes or runs low on memory, memcache won't just delete stuff arbitrarily because it feels like it. But I'd consider it bad practice to use memcache for something like this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文