/
caches_eaccelerator.php
executable file
·135 lines (121 loc) · 3.35 KB
/
caches_eaccelerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php /*
ocPortal
Copyright (c) ocProducts, 2004-2012
See text/EN/licence.txt for full licencing information.
NOTE TO PROGRAMMERS:
Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
**** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****
*/
/**
* @license http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
* @copyright ocProducts Ltd
* @package core
*/
class eacceleratorcache
{
/**
* (Plug-in replacement for memcache API) Get data from the persistant cache.
*
* @param mixed Key
* @param ?TIME Minimum timestamp that entries from the cache may hold (NULL: don't care)
* @return ?mixed The data (NULL: not found / NULL entry)
*/
function get($key,$min_cache_date=NULL)
{
if (function_exists('eaccelerator_get'))
{
$data=eaccelerator_get($key);
} elseif (function_exists('mmcache_get'))
{
$data=mmcache_get($key);
}
if (is_null($data)) return NULL;
if ((!is_null($min_cache_date)) && ($data[0]<$min_cache_date)) return NULL;
return unserialize($data[1]);
}
/**
* (Plug-in replacement for memcache API) Put data into the persistant cache.
*
* @param mixed Key
* @param mixed The data
* @param integer Various flags (parameter not used)
* @param integer The expiration time in seconds.
*/
function set($key,$data,$flags,$expire_secs)
{
unset($flags);
// Update list of e-objects
global $ECACHE_OBJECTS;
if (!array_key_exists($key,$ECACHE_OBJECTS))
{
$ECACHE_OBJECTS[$key]=1;
if (function_exists('eaccelerator_put'))
{
eaccelerator_put(get_file_base().'ECACHE_OBJECTS',$ECACHE_OBJECTS,0);
} elseif (function_exists('mmcache_put'))
{
mmcache_put(get_file_base().'ECACHE_OBJECTS',$ECACHE_OBJECTS,0);
}
}
if (function_exists('eaccelerator_put'))
{
eaccelerator_put($key,array(time(),serialize($data)),$expire_secs);
} elseif (function_exists('mmcache_put'))
{
mmcache_put($key,array(time(),serialize($data)),$expire_secs);
}
}
/**
* (Plug-in replacement for memcache API) Delete data from the persistant cache.
*
* @param mixed Key name
*/
function delete($key)
{
// Update list of e-objects
global $ECACHE_OBJECTS;
unset($ECACHE_OBJECTS[$key]);
if (function_exists('eaccelerator_put'))
{
eaccelerator_put(get_file_base().'ECACHE_OBJECTS',$ECACHE_OBJECTS,0);
} elseif (function_exists('mmcache_put'))
{
mmcache_put(get_file_base().'ECACHE_OBJECTS',$ECACHE_OBJECTS,0);
}
if (function_exists('eaccelerator_rm'))
{
eaccelerator_rm($key);
} elseif (function_exists('mmcache_rm'))
{
mmcache_rm($key);
}
}
/**
* (Plug-in replacement for memcache API) Remove all data from the persistant cache.
*/
function flush()
{
global $ECACHE_OBJECTS;
$ECACHE_OBJECTS=array();
if (function_exists('eaccelerator_rm'))
{
foreach (array_keys($ECACHE_OBJECTS) as $obkey)
{
eaccelerator_rm($obkey);
}
} elseif (function_exists('mmcache_rm'))
{
foreach (array_keys($ECACHE_OBJECTS) as $obkey)
{
mmcache_rm($obkey);
}
}
if (function_exists('eaccelerator_put'))
{
eaccelerator_put(get_file_base().'ECACHE_OBJECTS',$ECACHE_OBJECTS,0);
} elseif (function_exists('mmcache_put'))
{
mmcache_put(get_file_base().'ECACHE_OBJECTS',$ECACHE_OBJECTS,0);
}
}
}