Permalink
Browse files

Statically determine if a cache adapter is enabled.

In `Adaptable::enabled()` it first asks for an instance of the adapter, which might be fine with other adaptables but for caching this does not work correctly since you could get a fatal error.

~~~
Fatal error: Class 'Memcached' not found
~~~
  • Loading branch information...
1 parent 3829658 commit 5ea12d0066175dd862d4a65958e5cae7eb6920c2 Blaine Schmeisser committed Feb 21, 2013
Showing with 16 additions and 0 deletions.
  1. +16 −0 storage/Cache.php
View
@@ -290,6 +290,22 @@ public static function clear($name) {
$settings = static::config();
return (isset($settings[$name])) ? static::adapter($name)->clear() : false;
}
+
+ /**
+ * Determines if the adapter specified in the named configuration is enabled.
+ *
+ * `Enabled` can mean various things, e.g. having a PECL memcached extension compiled
+ * & loaded, as well as having the memcache server up & available.
+ *
+ * @param string $name The named configuration whose adapter will be checked.
+ * @return boolean True if adapter is enabled, false if not. This method will
+ * return null if no configuration under the given $name exists.
+ */
+ public static function enabled($name) {
+ $class = static::_class(static::_config($name), static::$_adapters);
+ return $class::enabled();
+ }
+
}
?>

3 comments on commit 5ea12d0

@nwp
nwp commented on 5ea12d0 Feb 23, 2013

Confused... are we using this fork?

@seven1m

Yea, we're using it.

@blainesch

This was merged into li3 today. They requested it be added to adaptable not cache though. I'll fix this on monday.

Please sign in to comment.