令牌/激活表还是 Memcache?
我最近发现的内存缓存引发了一股热潮,并为一切带来了新的可能性。
现在,当有人注册了我们的一项服务时,当我发送确认电子邮件时,我会在“令牌”表中创建“令牌”,该表有一个设定的有效期(通常为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该?不会。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.