2018-07-05 15:47:52 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Core\Cache;
|
|
|
|
use Friendica\BaseObject;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract class for common used functions
|
|
|
|
*
|
|
|
|
* Class AbstractCacheDriver
|
|
|
|
*
|
|
|
|
* @package Friendica\Core\Cache
|
|
|
|
*/
|
2018-07-05 15:54:20 -04:00
|
|
|
abstract class AbstractCacheDriver extends BaseObject
|
2018-07-05 15:47:52 -04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param string $key The original key
|
|
|
|
* @return string The cache key used for the cache
|
|
|
|
*/
|
2018-10-06 18:27:54 -04:00
|
|
|
protected function getCacheKey($key)
|
|
|
|
{
|
2018-07-07 10:15:03 -04:00
|
|
|
// We fetch with the hostname as key to avoid problems with other applications
|
2018-07-05 15:47:52 -04:00
|
|
|
return self::getApp()->get_hostname() . ":" . $key;
|
|
|
|
}
|
2018-10-06 18:27:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $keys A list of cached keys
|
|
|
|
* @return array A list of original keys
|
|
|
|
*/
|
|
|
|
protected function getOriginalKeys($keys)
|
|
|
|
{
|
|
|
|
if (empty($keys)) {
|
|
|
|
return [];
|
|
|
|
} else {
|
|
|
|
// Keys are prefixed with the node hostname, let's remove it
|
|
|
|
array_walk($keys, function (&$value) {
|
|
|
|
$value = preg_replace('/^' . self::getApp()->get_hostname() . ':/', '', $value);
|
|
|
|
});
|
|
|
|
|
|
|
|
sort($keys);
|
|
|
|
|
|
|
|
return $keys;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters a list for a given prefix
|
|
|
|
*
|
|
|
|
* @param array $list the list
|
|
|
|
* @param string|null $prefix the prefix
|
|
|
|
*
|
|
|
|
* @return array the filtered list
|
|
|
|
*/
|
|
|
|
protected function filterPrefix($list, $prefix = null)
|
|
|
|
{
|
|
|
|
if (empty($prefix)) {
|
|
|
|
return array_keys($list);
|
|
|
|
} else {
|
|
|
|
$result = [];
|
|
|
|
|
|
|
|
foreach (array_keys($list) as $key) {
|
|
|
|
if (strpos($key, $prefix) === 0) {
|
|
|
|
array_push($result, $key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-07-05 16:01:33 -04:00
|
|
|
}
|