I current utilize the APC "apc_store" function as a means to replace items in the cache that already exists, but I'm not sure if the TTL gets reset or not. I'd like to have it so it does NOT reset the TTL values.
views:
37answers:
1
+2
Q:
Does the function "apc_store" reset the TTL values when replacing a cache key that already exist?
+1
A:
The TTL you provided in apc_store will definitely overwrite the TTL of existing item. If you don't provide TTL, the item will never expire.
TTL is relative, number of seconds from now. If you want a fixed value, just use the same value on every apc_store call.
If you want the item expire at an absolute time, you need to store the time with your object and calculate TTL every time. For example,
$obj = apc_fetch($key);
if (!$obj) {
$obj = new MyObject();
$obj->expiry = time() + 24*60*60; // Expires 24 hours later
}
$ttl = $obj->expiry - time();
if ($ttl <= 0) {
// Item expired
} else {
apc_store($key, $obj, $ttl);
}
ZZ Coder
2010-06-30 04:49:28