Page MenuHomeWickedGov Phorge

CachedList.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

CachedList.php

<?php
namespace MediaWiki\Extension\Notifications;
use UnexpectedValueException;
use Wikimedia\ObjectCache\WANObjectCache;
/**
* Caches an ContainmentList within WANObjectCache to prevent needing
* to load the nested list from a potentially slow source (mysql, etc).
*/
class CachedList implements ContainmentList {
private const ONE_WEEK = 4233600;
/** @var string[]|null */
private $result;
/**
* @param WANObjectCache $cache Bag to stored cached data in.
* @param string $partialCacheKey Partial cache key, $nestedList->getCacheKey() will be appended
* to this to construct the cache key used.
* @param ContainmentList $nestedList The nested EchoContainmentList to cache the result of.
* @param int $timeout How long in seconds to cache the nested list, defaults to 1 week.
*/
public function __construct(
protected WANObjectCache $cache,
protected string $partialCacheKey,
protected ContainmentList $nestedList,
protected int $timeout = self::ONE_WEEK,
) {
}
/**
* @inheritDoc
*/
public function getValues() {
if ( $this->result ) {
return $this->result;
}
$this->result = $this->cache->getWithSetCallback(
$this->getCacheKey(),
$this->timeout,
function () {
$result = $this->nestedList->getValues();
if ( !is_array( $result ) ) {
throw new UnexpectedValueException( sprintf(
"Expected array but received '%s' from '%s::getValues'",
get_debug_type( $result ),
get_class( $this->nestedList )
) );
}
return $result;
}
);
return $this->result;
}
/**
* @inheritDoc
*/
public function getCacheKey() {
return $this->cache->makeGlobalKey(
'echo-containment-list',
$this->partialCacheKey,
$this->nestedList->getCacheKey()
);
}
}

File Metadata

Mime Type
text/x-php
Expires
Mon, Nov 23, 16:31 (6 d, 32 m ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f0/41/bac70c3edd1869cd69f86a9f400e
Default Alt Text
CachedList.php (1 KB)

Event Timeline