Changeset 32482 in spip-zone
- Timestamp:
- Oct 29, 2009, 9:36:13 PM (11 years ago)
- Location:
- _plugins_/memoization/memo
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
_plugins_/memoization/memo/eaccelerator.inc
r32480 r32482 8 8 int cache_inc(string key[, int value[, int ttl] ]) 9 9 int cache_dec(string key[, int value[, int ttl] ]) 10 bool cache_lock(string key)11 bool cache_unlock(string key)10 null cache_lock(string key) 11 null cache_unlock(string key) 12 12 */ 13 13 … … 53 53 function cache_lock($key) { 54 54 eaccelerator_lock(_CACHE_NAMESPACE.$key); 55 return true;56 55 } 57 56 58 57 function cache_unlock($key) { 59 58 eaccelerator_unlock(_CACHE_NAMESPACE.$key); 60 return true;61 59 } 62 60 -
_plugins_/memoization/memo/filecache.inc
r32480 r32482 8 8 int cache_inc(string key[, int value[, int ttl] ]) 9 9 int cache_dec(string key[, int value[, int ttl] ]) 10 bool cache_lock(string key)11 bool cache_unlock(string key)10 null cache_lock(string key) 11 null cache_unlock(string key) 12 12 */ 13 13 … … 66 66 67 67 function cache_inc($key, $value=null, $ttl=null) { 68 while (!cache_lock($key)){ sleep(1); }68 cache_lock($key); 69 69 $value = (isset($value) ? intval($value) : 1) + intval(cache_get($key)); 70 70 cache_set($key, $value); … … 82 82 $f = cache_filename($key); 83 83 84 /* unlock */ 84 85 if ($unlock) { 85 return isset($locks[$f]) 86 AND is_resource($locks[$f]) 87 AND @flock($locks[$f], LOCK_UN) 88 AND @fclose($locks[$f]); 89 } else { 90 return ($locks[$f] = @fopen($f, 'a')) 91 AND @flock($locks[$f], LOCK_EX); 86 if (isset($locks[$f]) 87 AND is_resource($locks[$f])) { 88 @flock($locks[$f], LOCK_UN); 89 @fclose($locks[$f]); 90 unset($locks[$f]); 91 } 92 } 93 /* lock */ 94 else { 95 if (!isset($locks[$f])) { 96 $locks[$f] = @fopen($f, 'a'); 97 @flock($locks[$f], LOCK_EX); 98 } 92 99 } 93 100 } 94 101 95 102 function cache_unlock($key) { 96 returncache_lock($key, true);103 cache_lock($key, true); 97 104 } 98 105 -
_plugins_/memoization/memo/xcache.inc
r32480 r32482 15 15 16 16 @define('_CACHE_NAMESPACE', $_SERVER['HTTP_HOST'].':'); 17 @define('_LOCK_MAX', 30); # max lock time (seconds) 17 18 18 19 function cache_get($key) { … … 35 36 36 37 function cache_inc($key, $value=null, $ttl=null) { 37 return xcache_inc(_CACHE_NAMESPACE.$key, $value, $ttl); 38 $a = func_get_args(); 39 $a[0] = _CACHE_NAMESPACE.$key; 40 return call_user_func_array('xcache_inc', $a); 38 41 } 39 42 40 43 function cache_dec($key, $value=null, $ttl=null) { 41 return xcache_dec(_CACHE_NAMESPACE.$key, $value, $ttl); 44 $a = func_get_args(); 45 $a[0] = _CACHE_NAMESPACE.$key; 46 return call_user_func_array('xcache_dec', $a); 42 47 } 43 48 44 function cache_lock($key) { 45 return cache_inc('lock::'.$key)===1; 49 function cache_lock($key, /* private */ $unlock = false) { 50 static $locks = array(); 51 52 /* unlock */ 53 if ($unlock) { 54 unset($locks[$key]); 55 cache_unset('lock::'.$key); 56 } 57 /* lock */ 58 else { 59 if (!isset($locks[$key])) { 60 while (cache_isset('lock::'.$key) 61 OR cache_inc('lock::'.$key, 1, _LOCK_MAX) !== 1) 62 sleep (1); 63 register_shutdown_function('cache_lock', $key, true); 64 } 65 } 46 66 } 47 67 48 68 function cache_unlock($key) { 49 return cache_unset('lock::'.$key);69 cache_lock($key, true); 50 70 } 51 71
Note: See TracChangeset
for help on using the changeset viewer.