source: spip-zone/_plugins_/memoization/memo/eaccelerator.inc @ 32482

Last change on this file since 32482 was 32482, checked in by fil@…, 10 years ago

reglage des lock

File size: 1.4 KB
Line 
1<?php
2
3/*
4mixed cache_get(string key)
5bool  cache_set(string key, mixed value [, int ttl])
6bool  cache_isset(string key)
7bool  cache_unset(string key)
8int   cache_inc(string key[, int value[, int ttl] ])
9int   cache_dec(string key[, int value[, int ttl] ])
10null  cache_lock(string key)
11null  cache_unlock(string key)
12*/
13
14# http://bart.eaccelerator.net/doc/phpdoc/eAccelerator/_shared_memory_php.html
15
16@define('_CACHE_NAMESPACE', $_SERVER['HTTP_HOST'].':');
17
18function cache_get($key) {
19        return ($v = eaccelerator_get(_CACHE_NAMESPACE.$key))
20                ? @unserialize($v)
21                : null;
22}
23
24function cache_set($key, $value, $ttl = null) {
25        $value = serialize($value);
26        return is_null($ttl)
27                ? eaccelerator_put(_CACHE_NAMESPACE.$key, $value)
28                : eaccelerator_put(_CACHE_NAMESPACE.$key, $value, $ttl);
29}
30
31function cache_isset($key) {
32        return cache_get($key) !== null;
33}
34
35function cache_unset($key) {
36        return eaccelerator_rm(_CACHE_NAMESPACE.$key);
37}
38
39function cache_inc($key, $value=null, $ttl=null) {
40        eaccelerator_lock($key);
41        $value = isset($value) ? intval($value) : 1;
42        $value += intval(cache_get($key));
43        cache_set($key, $value, $ttl);
44        eaccelerator_unlock($key);
45        return $value;
46}
47
48function cache_dec($key, $value=null, $ttl=null) {
49        $value = isset($value) ? intval($value) : 1;
50        return cache_inc($key, -$value, $ttl);
51}
52
53function cache_lock($key) {
54        eaccelerator_lock(_CACHE_NAMESPACE.$key);
55}
56
57function cache_unlock($key) {
58        eaccelerator_unlock(_CACHE_NAMESPACE.$key);
59}
60
61?>
Note: See TracBrowser for help on using the repository browser.