function cache_set in APC - Alternative PHP Cache 6
Same name and namespace in other branches
- 5 apc.inc \cache_set()
Store data in the persistent cache.
Parameters
$cid: The cache ID of the data to store.
$bin: The bin/silo to store the data in. Valid core values are 'cache_filter', 'cache_menu', 'cache_page', or 'cache'.
$data: The data to store in the cache.
$expire: One of the following values:
- CACHE_PERMANENT: Indicates that the item should never be removed unless explicitly told to using cache_clear_all() with a cache ID.
- CACHE_TEMPORARY: Indicates that the item should be removed at the next general cache wipe.
- A Unix timestamp: Indicates that the item should be kept at least until the given time, after which it behaves like CACHE_TEMPORARY.
$headers: A string containing HTTP header information for cached pages.
File
- ./
apc.inc, line 51
Code
function cache_set($cid, $data, $bin = 'cache', $expire = CACHE_PERMANENT, $headers = NULL) {
// Create new cache object.
$cache = new stdClass();
$cache->cid = $cid;
$cache->created = time();
$cache->expire = $expire;
$cache->headers = $headers;
if (is_array($data) || is_object($data)) {
$cache->serialized = TRUE;
$cache->data = serialize($data);
}
else {
$cache->serialized = FALSE;
$cache->data = $data;
}
// If error on set, add it to the database cache
if (!apc_handle_set($cid, $cache, $expire, $bin)) {
watchdog("Unable to set apc cache: {$bin} -> {$cid}", WATCHDOG_ERROR);
}
}