|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-11-03 11:42 UTC] rasmus@php.net
[2006-11-03 12:16 UTC] rasmus@php.net
[2006-11-03 13:30 UTC] apc at tequilasolutions dot com
[2006-11-20 02:45 UTC] gopalv82 at yahoo dot com
[2009-03-22 19:47 UTC] shire@php.net
[2009-05-05 14:47 UTC] shire@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 03:00:01 2025 UTC |
Description: ------------ I've been using apc_store to cache the results of complex queries, the cached values are valid until the database changes. I always store the last update time and can retrieve it with get_last_modified_date() Basically, I needed an apc_fetch($key,$udt) that only returns the data if the cached value is newer than the passed udt, otherwise dumps the cached value. Reproduce code: --------------- I've written some wrappers to provide the functionality, but some way to use apc_fetch conditionally depending on how old the cached value is would probably be a useful feature. function apc_fetch_udt($key){ global $no_sql_cache; if (isset($no_sql_cache) and $no_sql_cache) return; $g = apc_fetch($key); if ($g){ list($udt,$val) = $g; if (get_last_modified_date()<$udt) { $val = unserialize($val); return $val; } else { apc_delete($key); } } } function apc_store_udt($key,$g){ global $no_sql_cache; if (isset($no_sql_cache) and $no_sql_cache) return; $udt = time(); $g = serialize($g); $apc = array($udt,$g); apc_store($key, $apc); } Expected result: ---------------- Just as an aside, I've been getting locking problems with my server going into deadlock using apc_store, I've tried using normal and semaphore locks and can't find much on the net about problems with apc_store apart from it perhaps has problems when storing arrays of thousands of items (which I am doing). Any advise on programming practice to avoid deadlock when using apc_store would be appreciated. Actual result: -------------- Thanks Steve