如何在不影响 ttl 的情况下,在 zend 框架 2 中为 memcache 中的单个记录设置过期时间


How to set expiration time for individual records in memcache in zend framework 2 without affecting the ttl

我有一个要求,我需要为 zend framework2 中的值设置 30 分钟的过期时间,即 1800 秒,但默认 ttl 是 10 分钟,即 600 秒。

这个想法是,对于这个单独的记录,过期时间将与默认的 ttl 不同,这应该不会影响 memcache 中设置的先前和后续记录的过期时间。

根据您的要求,如果要设置不同的 TTL 时间,则必须为每条记录定义唯一键

$memcache->set('recordKeyOne', $youRecordOne, false, 1800)
$memcache->set('recordKeyTwo', $youRecordTwo, false, 300)

这样,两个对象都将根据创建对象时设置的过期时间过期。