@@ -51,6 +51,11 @@ class evxCache {
51
51
*/
52
52
const LOCK_WAITING_REPEATS = 20 ;
53
53
54
+ /**
55
+ * Lifetime key value for keys without associated expire time
56
+ */
57
+ const NON_EXPIRATION_LIFETIME = -1 ;
58
+
54
59
/**
55
60
* Cache storage.
56
61
*
@@ -173,7 +178,7 @@ public function delete($entryName) {
173
178
* @param string $entryName Cache entry name
174
179
* @param mixed $data Data to store
175
180
*/
176
- public function save ($ entryName , $ data ){
181
+ public function save ($ entryName , $ data, $ nonExpiration = FALSE ){
177
182
$ saveRes = false ;
178
183
$ this ->store ($ entryName , $ data );
179
184
switch ($ this ->driver ){
@@ -184,7 +189,9 @@ public function save($entryName, $data){
184
189
$lifetime = time() + $cacheLifetime;
185
190
}*/
186
191
$ ttl = evxCache::DAY ;
187
- if (!$ lifetime ){
192
+ if ($ nonExpiration ){
193
+ $ lifetime = evxCache::NON_EXPIRATION_LIFETIME ;
194
+ }else if (!$ lifetime ){
188
195
// 1 day if cache lifetime is not set
189
196
$ lifetime = time () + evxCache::DAY ;
190
197
}else {
@@ -193,7 +200,11 @@ public function save($entryName, $data){
193
200
}
194
201
$ aCachedData = array ('lifetime ' => $ lifetime , 'data ' => $ data , 'lock ' => true );
195
202
if ('redis ' == $ this ->driver ){
196
- $ saveRes = $ this ->oDriver ->set ($ entryName , json_encode ($ aCachedData ), 'ex ' , $ ttl );
203
+ if ($ nonExpiration ){
204
+ $ saveRes = $ this ->oDriver ->set ($ entryName , json_encode ($ aCachedData ));
205
+ }else {
206
+ $ saveRes = $ this ->oDriver ->set ($ entryName , json_encode ($ aCachedData ), 'ex ' , $ ttl );
207
+ }
197
208
$ this ->oDriver ->getConnection ()->switchToSlave ();
198
209
}else {
199
210
$ saveRes = $ this ->oDriver ->set ($ entryName , $ aCachedData );
@@ -292,7 +303,7 @@ public function loadCachedData($entryName, $default = NULL, $cacheLifetime = FAL
292
303
$ memcachedData = ('redis ' == $ this ->driver ) ? json_decode ($ this ->oDriver ->get ($ entryName ), TRUE ) : $ this ->oDriver ->get ($ entryName );
293
304
if ($ memcachedData && isset ($ memcachedData ['lifetime ' ]) && isset ($ memcachedData ['data ' ])){
294
305
$ result ['data ' ] = $ memcachedData ['data ' ];
295
- if ($ memcachedData ['lifetime ' ] < time ()){
306
+ if ($ memcachedData ['lifetime ' ] > 0 && $ memcachedData [ ' lifetime ' ] < time ()){
296
307
$ result ['expired ' ] = TRUE ;
297
308
}
298
309
}
0 commit comments