namespace Friendica\Core\Cache;
use Friendica\Core\Cache;
+use Friendica\Core\Logger;
use Exception;
use Memcached;
/**
* Memcached Cache Driver
*
- * @author Hypolite Petovan <mrpetovan@gmail.com>
+ * @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class MemcachedCacheDriver extends AbstractCacheDriver implements IMemoryCacheDriver
{
$this->memcached = new Memcached();
array_walk($memcached_hosts, function (&$value) {
- $value = array_map('trim', explode(',', $value));
+ if (is_string($value)) {
+ $value = array_map('trim', explode(',', $value));
+ }
});
$this->memcached->addServers($memcached_hosts);
}
}
+ /**
+ * (@inheritdoc)
+ */
+ public function getAllKeys($prefix = null)
+ {
+ $keys = $this->getOriginalKeys($this->memcached->getAllKeys());
+
+ if ($this->memcached->getResultCode() == Memcached::RES_SUCCESS) {
+ return $this->filterArrayKeysByPrefix($keys, $prefix);
+ } else {
+ Logger::log('Memcached \'getAllKeys\' failed with ' . $this->memcached->getResultMessage(), Logger::ALL);
+ return [];
+ }
+ }
+
+ /**
+ * (@inheritdoc)
+ */
public function get($key)
{
$return = null;
if ($this->memcached->getResultCode() === Memcached::RES_SUCCESS) {
$return = $value;
+ } else {
+ Logger::log('Memcached \'get\' failed with ' . $this->memcached->getResultMessage(), Logger::ALL);
}
return $return;
}
+ /**
+ * (@inheritdoc)
+ */
public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
{
$cachekey = $this->getCacheKey($key);
$value
);
}
-
}
+ /**
+ * (@inheritdoc)
+ */
public function delete($key)
{
$cachekey = $this->getCacheKey($key);
return $this->memcached->delete($cachekey);
}
+ /**
+ * (@inheritdoc)
+ */
public function clear($outdated = true)
{
if ($outdated) {
}
/**
- * @brief Sets a value if it's not already stored
- *
- * @param string $key The cache key
- * @param mixed $value The old value we know from the cache
- * @param int $ttl The cache lifespan, must be one of the Cache constants
- * @return bool
+ * (@inheritdoc)
*/
public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
{