aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/cache.php9
-rw-r--r--engine/lib/memcache.php25
2 files changed, 27 insertions, 7 deletions
diff --git a/engine/lib/cache.php b/engine/lib/cache.php
index 0363f501b..23f3c302b 100644
--- a/engine/lib/cache.php
+++ b/engine/lib/cache.php
@@ -450,13 +450,8 @@
// TODO : hook out to the world ? (can't if using as object cache)
// Try and see if memcache is present & enabled
- try {
- if ((isset($CONFIG->memcache) && ($CONFIG->memcache=true)))
- return new ElggMemcache($namespace);
- } catch (Exception $e) {
- if ((isset($CONFIG->debug)) && ($CONFIG->debug == true))
- error_log("$e");
- }
+ if (is_memcache_available())
+ return new ElggMemcache($namespace);
return new ElggStaticVariableCache($namespace);
}
diff --git a/engine/lib/memcache.php b/engine/lib/memcache.php
index 8afef6302..ec3ebc783 100644
--- a/engine/lib/memcache.php
+++ b/engine/lib/memcache.php
@@ -213,4 +213,29 @@
$this->save_persistent_keylist();
}*/
}
+
+ /**
+ * Return true if memcache is available and configured.
+ *
+ * @return bool
+ */
+ function is_memcache_available()
+ {
+ global $CONFIG;
+
+ static $memcache_available;
+
+ if ((!isset($CONFIG->memcache)) || (!$CONFIG->memcache))
+ return false;
+
+ if (($memcache_available!==true) && ($memcache_available!==false)) // If we haven't set variable to something
+ {
+ try {
+ $tmp = new ElggMemcache();
+ $memcache_available = true; // No exception thrown so we have memcache available
+ } catch (Exception $e) { $memcache_available = false; }
+ }
+
+ return $memcache_available;
+ }
?> \ No newline at end of file