3 namespace Friendica\Core\Cache;
4 use Friendica\BaseObject;
8 * Abstract class for common used functions
10 * Class AbstractCacheDriver
12 * @package Friendica\Core\Cache
14 abstract class AbstractCacheDriver extends BaseObject
17 * Returns the prefix (to avoid namespace conflicts)
22 protected function getPrefix()
24 // We fetch with the hostname as key to avoid problems with other applications
25 return self::getApp()->getHostName();
29 * @param string $key The original key
30 * @return string The cache key used for the cache
33 protected function getCacheKey($key)
35 return $this->getPrefix() . ":" . $key;
39 * @param array $keys A list of cached keys
40 * @return array A list of original keys
42 protected function getOriginalKeys($keys)
47 // Keys are prefixed with the node hostname, let's remove it
48 array_walk($keys, function (&$value) {
49 $value = preg_replace('/^' . self::getApp()->getHostName() . ':/', '', $value);
59 * Filters the keys of an array with a given prefix
60 * Returns the filtered keys as an new array
62 * @param array $array The array, which should get filtered
63 * @param string|null $prefix The prefix (if null, all keys will get returned)
65 * @return array The filtered array with just the keys
67 protected function filterArrayKeysByPrefix($array, $prefix = null)
70 return array_keys($array);
74 foreach (array_keys($array) as $key) {
75 if (strpos($key, $prefix) === 0) {
76 array_push($result, $key);