function dmemcache_piece_cache_set in Memcache API and Integration 6
Same name and namespace in other branches
- 7 dmemcache.inc \dmemcache_piece_cache_set()
Track active keys with multi-piece values, necessary for efficient cleanup.
We can't use variable_get/set for tracking this information because if the variables array grows >1M and has to be split into pieces we'd get stuck in an infinite loop. Storing this information in memcache means it can be lost, but in that case the pieces will still eventually be auto-expired by memcache.
Parameters
string $cid: The cid of the root multi-piece value.
integer $exp: Timestamp when the cached item expires. If NULL, the $cid will be deleted.
Return value
bool TRUE on succes, FALSE otherwise.
2 calls to dmemcache_piece_cache_set()
- dmemcache_delete in ./
dmemcache.inc - Deletes an item from the cache.
- _dmemcache_set_pieces in ./
dmemcache.inc - Split a large item into pieces and place them into memcache
File
- ./
dmemcache.inc, line 808
Code
function dmemcache_piece_cache_set($cid, $exp = NULL) {
// Always refresh cached copy to minimize multi-thread race window.
$piece_cache =& dmemcache_static('dmemcache_piece_cache', array());
$piece_cache = dmemcache_get('__dmemcache_piece_cache');
if (!is_array($piece_cache)) {
$piece_cache = array();
}
if (isset($exp)) {
if ($exp <= 0) {
// If no expiration time is set, defaults to 30 days.
$exp = $_SERVER['REQUEST_TIME'] + 2592000;
}
$piece_cache[$cid] = $exp;
}
else {
unset($piece_cache[$cid]);
}
return dmemcache_set('__dmemcache_piece_cache', $piece_cache);
}