Get expiration time of a memcache item in php?

后端 未结 3 704
花落未央
花落未央 2021-01-19 14:18

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.

However, at that time the Twitt

3条回答
  •  误落风尘
    2021-01-19 14:46

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

    • If the cache is older than 30 minutes, attempt to pull from Twitter
    • If new data was successfully retrieved, overwrite the cache
    • Cache data for an indefinite amount of time (or much longer than you intend to cache anyway)
    • Note the last time the cache was updated (current time) in a separate key
    • Rinse, repeat

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

提交回复
热议问题