Skip to content

Commit 004910f

Browse files
committed
Added ability add non expiration data into cache.
1 parent 8a10238 commit 004910f

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

service/lib/cache.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class evxCache {
5151
*/
5252
const LOCK_WAITING_REPEATS = 20;
5353

54+
/**
55+
* Lifetime key value for keys without associated expire time
56+
*/
57+
const NON_EXPIRATION_LIFETIME = -1;
58+
5459
/**
5560
* Cache storage.
5661
*
@@ -173,7 +178,7 @@ public function delete($entryName) {
173178
* @param string $entryName Cache entry name
174179
* @param mixed $data Data to store
175180
*/
176-
public function save($entryName, $data){
181+
public function save($entryName, $data, $nonExpiration = FALSE){
177182
$saveRes = false;
178183
$this->store($entryName, $data);
179184
switch($this->driver){
@@ -184,7 +189,9 @@ public function save($entryName, $data){
184189
$lifetime = time() + $cacheLifetime;
185190
}*/
186191
$ttl = evxCache::DAY;
187-
if(!$lifetime){
192+
if($nonExpiration){
193+
$lifetime = evxCache::NON_EXPIRATION_LIFETIME;
194+
}else if(!$lifetime){
188195
// 1 day if cache lifetime is not set
189196
$lifetime = time() + evxCache::DAY;
190197
}else{
@@ -193,7 +200,11 @@ public function save($entryName, $data){
193200
}
194201
$aCachedData = array('lifetime' => $lifetime, 'data' => $data, 'lock' => true);
195202
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+
}
197208
$this->oDriver->getConnection()->switchToSlave();
198209
}else{
199210
$saveRes = $this->oDriver->set($entryName, $aCachedData);
@@ -292,7 +303,7 @@ public function loadCachedData($entryName, $default = NULL, $cacheLifetime = FAL
292303
$memcachedData = ('redis' == $this->driver) ? json_decode($this->oDriver->get($entryName), TRUE) : $this->oDriver->get($entryName);
293304
if($memcachedData && isset($memcachedData['lifetime']) && isset($memcachedData['data'])){
294305
$result['data'] = $memcachedData['data'];
295-
if($memcachedData['lifetime'] < time()){
306+
if($memcachedData['lifetime'] > 0 && $memcachedData['lifetime'] < time()){
296307
$result['expired'] = TRUE;
297308
}
298309
}

service/lib/ethplorer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ public function getTokenFullHistoryGrouped($updateCache = FALSE){
21802180
);
21812181
if(is_array($dbData) && !empty($dbData['result'])){
21822182
$result = $dbData['result'];
2183-
$this->oCache->save($cache, $result);
2183+
$this->oCache->save($cache, $result, $cacheLifetime ? FALSE : TRUE);
21842184
}
21852185
}
21862186
if(is_array($result) && sizeof($result)){

0 commit comments

Comments
 (0)