Skip to content
Permalink
Browse files
Merge pull request #743 from tarasfrompir/patch-4
Увеличено время сохранения кеша до недели
  • Loading branch information
sergejey committed May 25, 2020
2 parents 01edb9d + 30c41e4 commit fbb6e16782f3192ae4ed71da8f627768c2ca7053
Showing 2 changed files with 18 additions and 5 deletions.
@@ -4,10 +4,10 @@
* Summary of saveToCache
* @param mixed $key Key
* @param mixed $value Value
* @param mixed $ttl TTL (default 60)
* @param mixed $ttl TTL (532800) seconds (7 days)
* @return void
*/
function saveToCache($key, $value, $ttl = 60)
function saveToCache($key, $value, $ttl = 532800)
{
if (is_array($value) || strlen($value) > 255) return;

@@ -16,14 +16,12 @@ function saveToCache($key, $value, $ttl = 60)
$memory_cache[$key] = $value;
}

$rec = array('KEYWORD' => $key, 'DATAVALUE' => $value, 'EXPIRE' => date('Y-m-d H:i:s', time() + $ttl*60));
$rec = array('KEYWORD' => $key, 'DATAVALUE' => $value, 'EXPIRE' => date('Y-m-d H:i:s', time() + $ttl));
$sqlQuery = "REPLACE INTO cached_values (KEYWORD, DATAVALUE, EXPIRE) " .
" VALUES ('" . DbSafe1($rec['KEYWORD']) . "', " .
"'" . DbSafe1($rec['DATAVALUE']) . "'," .
"'" . $rec['EXPIRE'] . "')";
SQLExec($sqlQuery);
// почистим кеш
SQLExec("DELETE FROM cached_values WHERE EXPIRE < NOW()");
}

/**
@@ -1060,6 +1060,19 @@ function processObject($object_id)
return $result;
}

/**
* objects subscription events
*
* @access public
*/
function processSubscription($event, $details = '') {
if ($event == 'DAILY') {
// почистим кеш
SQLExec("DELETE FROM cached_values WHERE EXPIRE < NOW()");
}

}

/**
* Install
*
@@ -1069,6 +1082,7 @@ function processObject($object_id)
*/
function install($parent_name = "")
{
subscribeToEvent($this->name, 'DAILY');
parent::install($parent_name);
}

@@ -1081,6 +1095,7 @@ function install($parent_name = "")
*/
function uninstall()
{
unsubscribeFromEvent($this->name, 'DAILY');
SQLDropTable('objects');
parent::uninstall();
}

0 comments on commit fbb6e16

Please sign in to comment.