3 namespace Friendica\Core;
5 use Friendica\Core\Cache\ICache;
8 * Abstract class for common used functions
10 abstract class BaseCache implements ICache
13 * @var string The hostname
17 public function __construct(string $hostName)
19 $this->hostName = $hostName;
23 * Returns the prefix (to avoid namespace conflicts)
28 protected function getPrefix()
30 // We fetch with the hostname as key to avoid problems with other applications
31 return $this->hostName;
35 * @param string $key The original key
36 * @return string The cache key used for the cache
39 protected function getCacheKey($key)
41 return $this->getPrefix() . ":" . $key;
45 * @param array $keys A list of cached keys
46 * @return array A list of original keys
48 protected function getOriginalKeys($keys)
53 // Keys are prefixed with the node hostname, let's remove it
54 array_walk($keys, function (&$value) {
55 $value = preg_replace('/^' . $this->hostName . ':/', '', $value);
65 * Filters the keys of an array with a given prefix
66 * Returns the filtered keys as an new array
68 * @param array $keys The keys, which should get filtered
69 * @param string|null $prefix The prefix (if null, all keys will get returned)
71 * @return array The filtered array with just the keys
73 protected function filterArrayKeysByPrefix(array $keys, string $prefix = null)
80 foreach ($keys as $key) {
81 if (strpos($key, $prefix) === 0) {
82 array_push($result, $key);