MediaWiki REL1_34
CachingSiteStore.php
Go to the documentation of this file.
1<?php
2
31class CachingSiteStore implements SiteStore {
32
36 private $sites = null;
37
41 private $cacheKey;
42
47
51 private $cache;
52
56 private $siteStore;
57
64 public function __construct(
67 $cacheKey = null,
68 $cacheTimeout = 3600
69 ) {
70 $this->siteStore = $siteStore;
71 $this->cache = $cache;
72 $this->cacheKey = $cacheKey;
73 $this->cacheTimeout = $cacheTimeout;
74 }
75
90 private function getCacheKey() {
91 if ( $this->cacheKey === null ) {
92 $type = 'SiteList#' . SiteList::getSerialVersionId();
93 $this->cacheKey = $this->cache->makeKey( "sites/$type" );
94 }
95
96 return $this->cacheKey;
97 }
98
106 public function getSites() {
107 if ( $this->sites === null ) {
108 $this->sites = $this->cache->get( $this->getCacheKey() );
109
110 if ( !is_object( $this->sites ) ) {
111 $this->sites = $this->siteStore->getSites();
112
113 $this->cache->set( $this->getCacheKey(), $this->sites, $this->cacheTimeout );
114 }
115 }
116
117 return $this->sites;
118 }
119
129 public function getSite( $globalId ) {
130 $sites = $this->getSites();
131
132 return $sites->hasSite( $globalId ) ? $sites->getSite( $globalId ) : null;
133 }
134
144 public function saveSite( Site $site ) {
145 return $this->saveSites( [ $site ] );
146 }
147
157 public function saveSites( array $sites ) {
158 if ( empty( $sites ) ) {
159 return true;
160 }
161
162 $success = $this->siteStore->saveSites( $sites );
163
164 // purge cache
165 $this->reset();
166
167 return $success;
168 }
169
178 public function reset() {
179 // purge cache
180 $this->cache->delete( $this->getCacheKey() );
181 $this->sites = null;
182 }
183
193 public function clear() {
194 $this->reset();
195
196 return $this->siteStore->clear();
197 }
198
199}
Class representing a cache/ephemeral data store.
Definition BagOStuff.php:63
saveSites(array $sites)
SiteList null $sites
getCacheKey()
Constructs a cache key to use for caching the list of sites.
clear()
Clears the list of sites stored.
__construct(SiteStore $siteStore, BagOStuff $cache, $cacheKey=null, $cacheTimeout=3600)
reset()
Purges the internal and external cache of the site list, forcing the list.
static getSerialVersionId()
Returns the version ID that identifies the serialization structure used by getSerializationData() and...
Definition SiteList.php:310
hasSite( $globalSiteId)
Returns if the list contains the site with the provided global site identifier.
Definition SiteList.php:140
getSite( $globalSiteId)
Returns the Site with the provided global site identifier.
Definition SiteList.php:154
Definition Site.php:29