Skip to content

Commit

Permalink
[TASK] Adds check to only enable internal cache when opcache available
Browse files Browse the repository at this point in the history
References #818
  • Loading branch information
garvinhicking committed Nov 27, 2023
1 parent 6f6a8ed commit 12200fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,12 @@ function serendipity_url_allowed($url) {
// when Memcached and Redis are not used. Returns the configured cache object. Used internally by
// the other cache functions, you most likely never need to call this.
function serendipity_setupCache() {
global $serendipity;

if (!serendipity_db_bool($serendipity['useInternalCache'])) {
return false;
}

$cacheManager = new \voku\cache\CacheAdapterAutoManager();

$cacheManager->addAdapter(
Expand Down Expand Up @@ -1414,16 +1420,29 @@ static function () {

function serendipity_cleanCache() {
$cache = serendipity_setupCache();
if ($cache === false) {
return false;
}

return $cache->removeAll();
}

function serendipity_cacheItem($key, $item, $ttl = 3600) {
$cache = serendipity_setupCache();

if ($cache === false) {
return false;
}

return $cache->setItem($key, $item, $ttl);
}

function serendipity_getCacheItem($key) {
$cache = serendipity_setupCache();
if ($cache === false) {
return false;
}

return $cache->getItem($key);
}

Expand Down
5 changes: 5 additions & 0 deletions include/functions_config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ function serendipity_load_configuration($author = null) {
$serendipity['default_lang'] = $serendipity['lang'];
}

// Internal Cache relies on opcache features; disable when not available
if (serendipity_db_bool($serendipity['useInternalCache']) && !function_exists('opcache_get_status')) {
$serendipity['useInternalCache'] = false;
}

}

/**
Expand Down

0 comments on commit 12200fc

Please sign in to comment.