Permalink
Browse files

feature(core): added a new function to check if system_cache is enabled

fixes #9382
  • Loading branch information...
jdalsem committed Mar 17, 2016
1 parent 094ce5c commit f3bbff32ef8c0620ebb9ccd93b82504e8a1f6634
View
@@ -88,13 +88,17 @@
/**
* Is simplecache enabled?
*
* @see elgg_is_simplecache_enabled() Use this instead of reading the value.
*
* @global string $CONFIG->simplecache_enabled
*/
$CONFIG->simplecache_enabled;
/**
* Is the system cache enabled
*
* @see elgg_is_system_cache_enabled() Use this instead of reading the value.
*
* @global string $CONFIG->system_cache_enabled
*/
$CONFIG->system_cache_enabled;
@@ -253,16 +257,16 @@
/**
* This is an optional script used to override Elgg's default handling of
* uncaught exceptions.
*
*
* This should be an absolute file path to a php script that will be called
* any time an uncaught exception is thrown.
*
*
* The script will have access to the following variables as part of the scope
* global $CONFIG
* $exception - the unhandled exception
*
*
* @warning - the database may not be available
*
*
* @global string $CONFIG->exception_include
*/
$CONFIG->exception_include = '';
@@ -17,7 +17,7 @@ class SystemCache {
/**
* Global Elgg configuration
*
*
* @var \stdClass
*/
private $CONFIG;
@@ -71,8 +71,7 @@ function reset() {
*/
function save($type, $data) {
if ($this->CONFIG->system_cache_enabled) {
if ($this->isEnabled()) {
return $this->getFileCache()->save($type, $data);
}
@@ -87,8 +86,7 @@ function save($type, $data) {
*/
function load($type) {
if ($this->CONFIG->system_cache_enabled) {
if ($this->isEnabled()) {
$cached_data = $this->getFileCache()->load($type);
if ($cached_data) {
@@ -99,6 +97,15 @@ function load($type) {
return null;
}
/**
* Is system cache enabled
*
* @return bool
*/
function isEnabled() {
return (bool) $this->CONFIG->system_cache_enabled;
}
/**
* Enables the system disk cache.
*
@@ -133,7 +140,7 @@ function disable() {
/**
* Loads the system cache during engine boot
*
*
* @see elgg_reset_system_cache()
* @access private
*/
@@ -166,11 +173,11 @@ function loadAll() {
/**
* Initializes the simplecache lastcache variable and creates system cache files
* when appropriate.
*
*
* @access private
*/
function init() {
if (!$this->CONFIG->system_cache_enabled) {
if (!$this->isEnabled()) {
return;
}
@@ -182,7 +182,7 @@ function getLanguage() {
* @access private
*/
function loadTranslations($language = null) {
if ($this->CONFIG->system_cache_enabled) {
if (elgg_is_system_cache_enabled()) {
$loaded = true;
if ($language) {
View
@@ -51,6 +51,16 @@ function elgg_load_system_cache($type) {
return _elgg_services()->systemCache->load($type);
}
/**
* Is system cache enabled
*
* @return bool
* @since 2.2.0
*/
function elgg_is_system_cache_enabled() {
return _elgg_services()->systemCache->isEnabled();
}
/**
* Enables the system disk cache.
*
@@ -101,23 +111,23 @@ function elgg_register_simplecache_view($view_name) {
/**
* Get the URL for the cached view.
*
*
* Recommended usage is to just pass the entire view name as the first and only arg:
*
* ```
* $blog_js = elgg_get_simplecache_url('elgg/blog/save_draft.js');
* $favicon = elgg_get_simplecache_url('favicon.ico');
* ```
*
*
* For backwards compatibility with older versions of Elgg, this function supports
* "js" or "css" as the first arg, with the rest of the view name as the second arg:
*
* ```
* $blog_js = elgg_get_simplecache_url('js', 'elgg/blog/save_draft.js');
* ```
*
*
* This automatically registers the view with Elgg's simplecache.
*
*
* @param string $view The full view name
* @param string $subview If the first arg is "css" or "js", the rest of the view name
* @return string
@@ -163,7 +173,7 @@ function elgg_disable_simplecache() {
/**
* Recursively deletes a directory, including all hidden files.
*
*
* TODO(ewinslow): Move to filesystem package
*
* @param string $dir The directory
@@ -203,7 +213,7 @@ function elgg_invalidate_simplecache() {
/**
* Flush all the registered caches
*
*
* @return void
* @since 1.11
*/
@@ -214,7 +224,7 @@ function elgg_flush_caches() {
/**
* Initializes the simplecache lastcache variable and creates system cache files
* when appropriate.
*
*
* @access private
*/
function _elgg_cache_init() {
@@ -14,7 +14,7 @@
'system_cache' => array(
'type' => 'checkbox',
'value' => 1,
'checked' => elgg_get_config('system_cache_enabled') == 1,
'checked' => elgg_is_system_cache_enabled(),
'readonly' => false,
),
@@ -20,7 +20,7 @@
$elapsed = microtime(true) - $GLOBALS['START_MICROTIME'];
$query_count = _elgg_services()->db->getQueryCount();
$boot_cache_rebuilt = !elgg_get_config('_boot_cache_hit');
$system_cache = (bool)elgg_get_config('system_cache_enabled');
$system_cache = elgg_is_system_cache_enabled();
$yes = elgg_echo('option:yes');
$no = elgg_echo('option:no');
@@ -12,7 +12,7 @@
</p>
<?php
$simple_cache = elgg_get_config('simplecache_enabled');
$system_cache = elgg_get_config('system_cache_enabled');
$system_cache = elgg_is_system_cache_enabled();
if ($simple_cache || $system_cache) {
$advanced = elgg_view('output/url', array(
@@ -42,7 +42,7 @@
$system_cache_input = elgg_view("input/checkbox", array(
'label' => elgg_echo('installation:systemcache:label'),
'name' => 'system_cache_enabled',
'checked' => (bool)elgg_get_config('system_cache_enabled'),
'checked' => elgg_is_system_cache_enabled(),
))
?>

0 comments on commit f3bbff3

Please sign in to comment.