Comparing `CRM_Utils_Cache_Interface::get()` and `Psr\SimpleCache\CacheInterface::get()`,
they agree on key details:
1. They return values are `mixed` (strings, arrays, numbers,, etc)
2. The default representation of a cache-miss is NULL.
They differ in that PSR-16 allows the caller to optionally specify a `$default`.
Since no existing callers actually use this, we can (for moment) throw an
error if someone tries to pass `$default` to a driver that doesn't support
it.
See also: https://www.php-fig.org/psr/psr-16/
/**
* @param $key
+ * @param mixed $default
*
* @return mixed
*/
- public function get($key) {
+ public function get($key, $default = NULL) {
+ if ($default !== NULL) {
+ throw new \RuntimeException("FIXME: " . __CLASS__ . "::get() only supports NULL default");
+ }
return apc_fetch($this->_prefix . $key);
}
/**
* @param string $key
+ * @param mixed $default
*
* @return mixed
*/
- public function get($key) {
- return CRM_Utils_Array::value($key, $this->_cache);
+ public function get($key, $default = NULL) {
+ return CRM_Utils_Array::value($key, $this->_cache, $default);
}
/**
* Get a value from the cache.
*
* @param string $key
+ * @param mixed $default
* @return mixed
- * NULL if $key has not been previously set
+ * The previously set value value, or $default (NULL).
*/
- public function get($key);
+ public function get($key, $default = NULL);
/**
* Delete a value from the cache.
/**
* @param $key
+ * @param mixed $default
*
* @return mixed
*/
- public function &get($key) {
+ public function get($key, $default = NULL) {
+ if ($default !== NULL) {
+ throw new \RuntimeException("FIXME: " . __CLASS__ . "::get() only supports NULL default");
+ }
$result = $this->_cache->get($this->_prefix . $key);
return $result;
}
/**
* @param $key
+ * @param mixed $default
*
* @return mixed
*/
- public function &get($key) {
+ public function get($key, $default = NULL) {
+ if ($default !== NULL) {
+ throw new \RuntimeException("FIXME: " . __CLASS__ . "::get() only supports NULL default");
+ }
$key = $this->cleanKey($key);
$result = $this->_cache->get($key);
return $result;
/**
* @param string $key
+ * @param mixed $default
*
* @return null
*/
- public function get($key) {
- return NULL;
+ public function get($key, $default = NULL) {
+ return $default;
}
/**
/**
* @param $key
+ * @param mixed $default
*
* @return mixed
*/
- public function get($key) {
+ public function get($key, $default = NULL) {
$result = $this->_cache->get($this->_prefix . $key);
- return ($result === FALSE) ? NULL : unserialize($result);
+ return ($result === FALSE) ? $default : unserialize($result);
}
/**
/**
* @param string $key
+ * @param mixed $default
*
* @return mixed
*/
- public function get($key) {
+ public function get($key, $default = NULL) {
+ if ($default !== NULL) {
+ throw new \RuntimeException("FIXME: " . __CLASS__ . "::get() only supports NULL default");
+ }
+
if (array_key_exists($key, $this->_cache)) {
return $this->_cache[$key];
}
/**
* @param string $key
+ * @param mixed $default
*
* @return mixed
*/
- public function get($key) {
+ public function get($key, $default = NULL) {
+ if ($default !== NULL) {
+ throw new \RuntimeException("FIXME: " . __CLASS__ . "::get() only supports NULL default");
+ }
if (!array_key_exists($key, $this->frontCache)) {
$this->frontCache[$key] = CRM_Core_BAO_Cache::getItem($this->group, $key, $this->componentID);
}