MediaWiki 1.44.0
CachingSiteStore.php
Go to the documentation of this file.
1<?php
22
24
33class CachingSiteStore implements SiteStore {
35 private $siteStore;
37 private $cache;
39 private $cacheKey = null;
41 private $sites = null;
42
43 public function __construct(
44 SiteStore $siteStore,
45 BagOStuff $cache
46 ) {
47 $this->siteStore = $siteStore;
48 $this->cache = $cache;
49 }
50
65 private function getCacheKey() {
66 if ( $this->cacheKey === null ) {
68 $this->cacheKey = $this->cache->makeKey( 'site-SiteList', $version );
69 }
70
71 return $this->cacheKey;
72 }
73
80 public function getSites() {
81 if ( $this->sites === null ) {
82 $this->sites = $this->cache->getWithSetCallback(
83 $this->getCacheKey(),
84 BagOStuff::TTL_HOUR,
85 function () {
86 return $this->siteStore->getSites();
87 }
88 );
89 }
90
91 return $this->sites;
92 }
93
101 public function getSite( $globalId ) {
102 $sites = $this->getSites();
103
104 return $sites->hasSite( $globalId ) ? $sites->getSite( $globalId ) : null;
105 }
106
114 public function saveSite( Site $site ) {
115 return $this->saveSites( [ $site ] );
116 }
117
125 public function saveSites( array $sites ) {
126 if ( !$sites ) {
127 return true;
128 }
129
130 $success = $this->siteStore->saveSites( $sites );
131
132 // purge cache
133 $this->reset();
134
135 return $success;
136 }
137
144 public function reset() {
145 $this->cache->delete( $this->getCacheKey() );
146 $this->sites = null;
147 }
148
159 public function clear() {
160 $this->reset();
161
162 return $this->siteStore->clear();
163 }
164
165}
166
168class_alias( CachingSiteStore::class, 'CachingSiteStore' );
Wrap SiteList with an in-process cache and (optionally) a local-server cache.
clear()
Clears the list of sites stored.
reset()
Purge the internal and external cache of the site list, forcing the list.
__construct(SiteStore $siteStore, BagOStuff $cache)
Array-like collection of Site objects.
Definition SiteList.php:37
static getSerialVersionId()
Returns the version ID that identifies the serialization structure used by __serialize() and unserial...
Definition SiteList.php:391
hasSite( $globalSiteId)
Returns if the list contains the site with the provided global site identifier.
Definition SiteList.php:222
getSite( $globalSiteId)
Returns the Site with the provided global site identifier.
Definition SiteList.php:236
Represents a single site.
Definition Site.php:36
Abstract class for any ephemeral data store.
Definition BagOStuff.php:87
Interface for storing and retrieving Site objects.
Definition SiteStore.php:32