获取PHP中的内存缓存项的过期时间? [英] Get expiration time of a memcache item in php?

查看:579
本文介绍了获取PHP中的内存缓存项的过期时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在网站上缓存推文(有效期为30分钟).当缓存为空时,第一个找到的用户将重新填充它.

I'm caching tweets on my site (with 30 min expiration time). When the cache is empty, the first user to find out will repopulate it.

但是,那时Twitter API可能返回200.在这种情况下,我想将之前的数据再延长30分钟.但是以前的数据将已经丢失.

However, at that time the Twitter API may return a 200. In that case I'd like to prolong the previous data for another 30 mins. But the previous data will already be lost.

因此,我想研究一下重新填充缓存,例如,在到期时间前5分钟,这样我就不会丢失任何日期.

So instead I'd like to look into repopulating the cache, say, 5 minutes before expiration time so that I don't lose any date.

那么,当我使用php的memcache :: get()时,如何知道某项的过期时间?

So how do I know the expiration time of an item when using php's memcache::get()?

此外,还有更好的方法吗?

Also, is there a better way of doing this?

推荐答案

在这种情况下,这不是更好的逻辑吗?

In that case, isn't this the better logic?

  • 如果缓存时间早于30分钟,请尝试从Twitter提取
  • 如果成功检索到新数据,则覆盖缓存
  • 无限期地缓存数据(或比您打算缓存的时间长得多)
  • 请注意,上次更新缓存的时间(当前时间)位于单独的键中
  • 冲洗,重复

重点是,仅在有新数据的情况下替换数据,不要让旧数据自动丢弃.

The point being, only replace the data with something new if you have it, don't let the old data be thrown away automatically.

这篇关于获取PHP中的内存缓存项的过期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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