31 protected int $ttl = 86400;
46 public function __construct(
protected string $namespace,
protected Config $config,
protected int $flags,
protected bool $validate_lastcache =
true) {
60 if ($this->disabled) {
69 if (is_int($expire_after)) {
70 $item->expiresAfter($expire_after);
72 $item->expiresAt($expire_after);
75 return $this->pool->save(
$item);
86 if ($this->disabled) {
92 if (!
$item->isHit()) {
96 if ($this->validate_lastcache && $this->config->lastcache) {
99 if (
$item->getCreationDate()->getTimestamp() < $expiration_date->getTimestamp()) {
106 }
catch (PhpfastcacheRootException $e) {
108 elgg_log($e->getMessage(),
'ERROR');
117 if ($this->disabled) {
128 return $this->pool->clear();
158 $this->
namespace = $namespace;
167 return $this->namespace;
180 return "{$this->getNamespace()}_{$id}";
195 if (!is_string(
$key) && !is_int(
$key)) {
199 return str_replace([
'{',
'}',
'(',
')',
'/',
'\\',
'@',
':'],
'_',
"{$key}");
208 protected function createPool(): ExtendedCacheItemPoolInterface {
216 $drivers = array_filter($drivers);
218 if (empty($drivers)) {
222 if (!empty($ephemeral)) {
223 $drivers[] = $ephemeral;
227 if (empty($drivers)) {
231 if (
count($drivers) === 1) {
232 return array_shift($drivers);
235 $cluster =
new ClusterAggregator($this->
getNamespace());
236 foreach ($drivers as $driver) {
237 $cluster->aggregateDriver($driver);
240 $cluster_driver = $cluster->getCluster();
241 $cluster_driver->setConfig(
new ConfigurationOption([
242 'useStaticItemCaching' =>
true,
243 'itemDetailedDate' =>
true,
246 return $cluster_driver;
254 if (!($this->flags & self::CACHE_PERSISTENT)) {
258 if (!self::isRedisAvailable()) {
275 if (!($this->flags & self::CACHE_PERSISTENT)) {
279 if (!self::isMemcacheAvailable()) {
296 if (!($this->flags & self::CACHE_FILESYSTEM)) {
307 }
catch (\Phpfastcache\Exceptions\PhpfastcacheIOException $e) {
308 if (!$this->config->installer_running) {
309 elgg_log($e, \Psr\Log\LogLevel::ERROR);
321 if (!($this->flags & self::CACHE_LOCALFILESYSTEM)) {
332 }
catch (\Phpfastcache\Exceptions\PhpfastcacheIOException $e) {
333 if (!$this->config->installer_running) {
334 elgg_log($e, \Psr\Log\LogLevel::ERROR);
346 if (!($this->flags & self::CACHE_RUNTIME)) {
350 $config = new \Phpfastcache\Drivers\Memory\Config();
352 $config->setUseStaticItemCaching(
true);
353 $config->setItemDetailedDate(
true);
363 if (!($this->flags & self::CACHE_BLACK_HOLE)) {
367 $config = new \Phpfastcache\Drivers\Devnull\Config();
380 return class_exists(
'Memcached');
391 return extension_loaded(
'Redis');
static isMemcacheAvailable()
Helper function to check if memcache is available.
int $ttl
TTL of saved items (default timeout after a day to prevent anything getting too stale) ...
A generic parent class for Configuration exceptions.
Exception thrown if an argument is not of the expected type.
static fromElggConfig(string $namespace,\Elgg\Config $config)
Factory to return a config object to be used when starting a driver.
Saves user notification settings.
__construct(protected string $namespace, protected Config $config, protected int $flags, protected bool $validate_lastcache=true)
Constructor.
getNamespace()
Get the namespace currently defined.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
load($key)
Load data from the cache using a given key.
prefixInstanceId(string $id)
Prefixes instance ids with namespace.
buildEphemeralDriver()
Builds in-memory driver.
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
setNamespace($namespace= 'default')
Set the namespace of this cache.
$config
Advanced site settings, debugging section.
sanitizeItemKey($key)
Sanitizes item key for cache.
if(!$entity instanceof\ElggUser) $data
buildMemcachedDriver()
Builds Memcached driver.
save($key, $data, $expire_after=null)
Save data in a cache.
static fromElggConfig(string $namespace,\Elgg\Config $config)
Factory to return a config object to be used when starting a driver.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
static fromElggConfig(string $namespace,\Elgg\Config $config)
Factory to return a config object to be used when starting a driver.
The Elgg cache base class.
const CACHE_LOCALFILESYSTEM
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Extension of the DateTime class to support formatting a date using the locale.
createPool()
Create a new cluster/pool of drivers.
static isRedisAvailable()
Helper function to check if Redis is available.
buildRedisDriver()
Builds Redis driver.
static normalizeTime($time)
Returns DateTime object based on time representation.
buildLocalFileSystemDriver()
Builds local file system driver.
buildBlackHoleDriver()
Builds null cache driver.
$id
Generic annotation delete action.
buildFileSystemDriver()
Builds file system driver.
static fromElggConfig(string $namespace,\Elgg\Config $config)
Factory to return a config object to be used when starting a driver.