Fix internal cache, init proper functions API

This commit is contained in:
onli 2019-02-16 13:07:53 +01:00
parent fd00877141
commit 4c4545428d
4 changed files with 35 additions and 35 deletions

View File

@ -2,6 +2,14 @@
Version 2.2.1-alpha2 ()
------------------------------------------------------------------------
* Add internal cache invalidation when comment is added
* Move cache into functions.inc.php, resulting in this API:
* serendipity_setupCache() (used internally)
* serendipity_cleanCache()
* serendipity_cacheItem($key, $item, $ttl = 3600)
* serendipity_getCacheItem($key)
* Drop deprecated serendipity_purgeEntry function
* Default settings: Disable entryproperties cache, enable internal

View File

@ -1374,5 +1374,26 @@ function serendipity_url_allowed($url) {
return true;
}
use voku\cache\Cache;
function serendipity_setupCache() {
$cache = new Cache();
return $cache;
}
function serendipity_cleanCache() {
$cache = serendipity_setupCache();
return $cache->removeAll();
}
function serendipity_cacheItem($key, $item, $ttl = 3600) {
$cache = serendipity_setupCache();
return $cache->setItem($key, $item, $ttl);
}
function serendipity_getCacheItem($key) {
$cache = serendipity_setupCache();
return $cache->getItem($key);
}
define("serendipity_FUNCTIONS_LOADED", true);
/* vim: set sts=4 ts=4 expandtab : */

View File

@ -722,7 +722,7 @@ function serendipity_approveComment($cid, $entry_id, $force = false, $moderate =
serendipity_plugin_api::hook_event('backend_approvecomment', $rs);
}
serendipity_cleanCache();
if ($flip) {
if ($moderate) return -1; // comment set to pending
if (!$moderate) return 1; // comment set to approved
@ -942,7 +942,7 @@ function serendipity_insertComment($id, $commentInfo, $type = 'NORMAL', $source
if ($GLOBALS['tb_logging']) {
fclose($fp);
}
serendipity_cleanCache();
return $cid;
}

View File

@ -210,12 +210,11 @@ function &serendipity_fetchEntries($range = null, $full = true, $limit = '', $fe
$initial_args = array_values(func_get_args());
if ($serendipity['useInternalCache']) {
$cache = serendipity_setupCache();
$key = md5(serialize($initial_args) . $serendipity['short_archives'] . '||' . $serendipity['range'] . '||' . $serendipity['GET']['category'] . '||' . $serendipity['GET']['hide_category'] . '||' . $serendipity['GET']['viewAuthor'] . '||' . $serendipity['GET']['page'] . '||' . $serendipity['fetchLimit'] . '||' . $serendipity['max_fetch_limit'] . '||' . $serendipity['GET']['adminModule'] . '||' . serendipity_checkPermission('adminEntriesMaintainOthers') . '||' .$serendipity['showFutureEntries'] . '||' . $serendipity['archiveSortStable'] . '||' . $serendipity['plugindata']['smartyvars']['uriargs'] );
$entries = $cache->getItem($key);
$entries = serendipity_getCacheItem($key);
if ($entries && $entries !== false) {
$serendipity['fullCountQuery'] = $cache->getItem($key . '_fullCountQuery');
$serendipity['fullCountQuery'] = serendipity_getCacheItem($key . '_fullCountQuery');
return unserialize($entries);
}
}
@ -464,8 +463,8 @@ function &serendipity_fetchEntries($range = null, $full = true, $limit = '', $fe
if ($serendipity['useInternalCache']) {
$key = md5(serialize($initial_args) . $serendipity['short_archives'] . '||' . $serendipity['range'] . '||' . $serendipity['GET']['category'] . '||' . $serendipity['GET']['hide_category'] . '||' . $serendipity['GET']['viewAuthor'] . '||' . $serendipity['GET']['page'] . '||' . $serendipity['fetchLimit'] . '||' . $serendipity['max_fetch_limit'] . '||' . $serendipity['GET']['adminModule'] . '||' . serendipity_checkPermission('adminEntriesMaintainOthers') . '||' .$serendipity['showFutureEntries'] . '||' . $serendipity['archiveSortStable'] . '||' . $serendipity['plugindata']['smartyvars']['uriargs']);
$cache->setItem($key, serialize($ret));
$cache->setItem($key . '_fullCountQuery', $serendipity['fullCountQuery']);
serendipity_cacheItem($key, serialize($ret));
serendipity_cacheItem($key . '_fullCountQuery', $serendipity['fullCountQuery']);
}
return $ret;
@ -1291,34 +1290,6 @@ function serendipity_printEntries($entries, $extended = 0, $preview = false, $sm
} // end function serendipity_printEntries
function serendipity_cleanCache() {
$cache = serendipity_setupCache();
return $cache->removeAll();
}
//function serendipity_setupCache() {
//include_once 'Cache/Lite.php';
//if (!class_exists('Cache_Lite')) {
//return false;
//}
//$options = array(
//'cacheDir' => $serendipity['serendipityPath'] . 'templates_c/',
//'lifeTime' => 3600,
//'hashedDirectoryLevel' => 2
//);
//return new Cache_Lite($options);
//}
use voku\cache\Cache;
function serendipity_setupCache() {
$cache = new Cache();
$ttl = 3600; // 60s * 60 = 1h
return $cache;
}
/**
* Inserts a new entry into the database or updates an existing entry