MediaWiki  1.32.5
CachingSiteStore.php
Go to the documentation of this file.
1 <?php
2 
31 class CachingSiteStore implements SiteStore {
32 
36  private $sites = null;
37 
41  private $cacheKey;
42 
46  private $cacheTimeout;
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 }
SiteList\getSerialVersionId
static getSerialVersionId()
Returns the version ID that identifies the serialization structure used by getSerializationData() and...
Definition: SiteList.php:310
CachingSiteStore\saveSite
saveSite(Site $site)
Definition: CachingSiteStore.php:144
CachingSiteStore
Definition: CachingSiteStore.php:31
CachingSiteStore\$cacheTimeout
int $cacheTimeout
Definition: CachingSiteStore.php:46
SiteList\hasSite
hasSite( $globalSiteId)
Returns if the list contains the site with the provided global site identifier.
Definition: SiteList.php:140
BagOStuff
Class representing a cache/ephemeral data store.
Definition: BagOStuff.php:58
$success
$success
Definition: NoLocalSettings.php:42
CachingSiteStore\clear
clear()
Clears the list of sites stored.
Definition: CachingSiteStore.php:193
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
CachingSiteStore\reset
reset()
Purges the internal and external cache of the site list, forcing the list.
Definition: CachingSiteStore.php:178
SiteStore
Definition: SiteStore.php:29
SiteList
Definition: SiteList.php:29
CachingSiteStore\getCacheKey
getCacheKey()
Constructs a cache key to use for caching the list of sites.
Definition: CachingSiteStore.php:90
CachingSiteStore\$cache
BagOStuff $cache
Definition: CachingSiteStore.php:51
CachingSiteStore\$sites
SiteList null $sites
Definition: CachingSiteStore.php:36
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
CachingSiteStore\saveSites
saveSites(array $sites)
Definition: CachingSiteStore.php:157
CachingSiteStore\$cacheKey
string null $cacheKey
Definition: CachingSiteStore.php:41
Site
Definition: Site.php:29
CachingSiteStore\$siteStore
SiteStore $siteStore
Definition: CachingSiteStore.php:56
CachingSiteStore\__construct
__construct(SiteStore $siteStore, BagOStuff $cache, $cacheKey=null, $cacheTimeout=3600)
Definition: CachingSiteStore.php:64
SiteList\getSite
getSite( $globalSiteId)
Returns the Site with the provided global site identifier.
Definition: SiteList.php:154
CachingSiteStore\getSites
getSites()
Definition: CachingSiteStore.php:106
CachingSiteStore\getSite
getSite( $globalId)
Definition: CachingSiteStore.php:129
$type
$type
Definition: testCompression.php:48