If you are using the Zend version of php, this is easy.
You do not need to serialize the data.
Only content can be cached. Resources, such as file descriptors, cannot. To keep true / false, use 1.0 so that you can distinguish the cache from the result with ===.
Store:
zend_shm_cache_store('cache_namespace::this_cache_name',$any_variable,$expire_in_seconds);
Download:
$any_variable = zend_shm_cache_fetch('cache_namespace::this_cache_name');
if ( $any_variable === false ) {
}
For long-term data, you can use:
zend_disk_cache_store();zend_disk_cache_fetch();
For those who do not have zend, the corresponding APC versions above are:
Store:
apc_store('cache_name',$any_variable,$expire_in_seconds);
Download:
$any_variable = apc_fetch('cache_name');
if ( $any_variable === false ) {
}
.
, /unserialize . , , zend , concurrency :
Store:
file_put_contents('/tmp/some_filename',serialize($any_variable));
:
$any_variable = unserialize(file_get_contents('/tmp/some_filename') );
: concurrency , , - . psuedo , .
Psuedo:
while ( lock exists ) {
microsleep;
}
get lock.
check we got lock.
write value.
release lock.