getCacheKey() will be appended * to this to construct the cache key used. * @param EchoContainmentList $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( BagOStuff $cache, $partialCacheKey, EchoContainmentList $nestedList, $timeout = self::ONE_WEEK ) { $this->cache = $cache; $this->partialCacheKey = $partialCacheKey; $this->nestedList = $nestedList; $this->timeout = $timeout; } /** * @inheritDoc */ public function getValues() { if ( $this->result ) { return $this->result; } $cacheKey = $this->getCacheKey(); $fetched = $this->cache->get( $cacheKey ); if ( is_array( $fetched ) ) { $this->result = $fetched; return $this->result; } $result = $this->nestedList->getValues(); if ( !is_array( $result ) ) { throw new MWException( sprintf( "Expected array but received '%s' from '%s::getValues'", is_object( $result ) ? get_class( $result ) : gettype( $result ), get_class( $this->nestedList ) ) ); } $this->cache->set( $cacheKey, $result, $this->timeout ); $this->result = $result; return $this->result; } /** * @inheritDoc */ public function getCacheKey() { return $this->partialCacheKey . '_' . $this->nestedList->getCacheKey(); } }