Go to the documentation of this file.
23 use Wikimedia\ObjectFactory;
68 if ( empty(
$params[
'caches'] ) || !is_array(
$params[
'caches'] ) ) {
69 throw new InvalidArgumentException(
70 __METHOD__ .
': "caches" parameter must be an array of caches'
75 foreach (
$params[
'caches']
as $cacheInfo ) {
77 $this->caches[] = $cacheInfo;
79 if ( !isset( $cacheInfo[
'args'] ) ) {
84 $cacheInfo[
'args'] = [ $cacheInfo ];
86 $this->caches[] = ObjectFactory::getObjectFromSpec( $cacheInfo );
91 $this->asyncWrites = (
92 isset(
$params[
'replication'] ) &&
93 $params[
'replication'] ===
'async' &&
94 is_callable( $this->asyncHandler )
97 $this->cacheIndexes = array_keys( $this->caches );
101 foreach ( $this->caches
as $cache ) {
106 public function get( $key, $flags = 0 ) {
111 return $this->caches[0]->get( $key, $flags );
116 foreach ( $this->caches
as $i =>
$cache ) {
126 && ( $flags & self::READ_VERIFIED ) == self::READ_VERIFIED
133 [ $key,
$value, self::UPGRADE_TTL ]
139 public function set( $key,
$value, $exptime = 0, $flags = 0 ) {
148 public function delete( $key, $flags = 0 ) {
157 public function add( $key,
$value, $exptime = 0, $flags = 0 ) {
171 array_slice( $this->cacheIndexes, 1 ),
174 [ $key,
$value, $exptime, $flags ]
181 public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
190 public function changeTTL( $key, $exptime = 0, $flags = 0 ) {
199 public function lock( $key, $timeout = 6, $expiry = 6, $rclass =
'' ) {
201 return $this->caches[0]->lock( $key, $timeout, $expiry, $rclass );
206 return $this->caches[0]->unlock( $key );
218 foreach ( $this->caches
as $cache ) {
219 if (
$cache->deleteObjectsExpiringBefore( $date, $progressCallback ) ) {
231 $val = $this->
get( $key, $flags );
232 if ( $val !==
false ) {
286 return $this->caches[0]->getLastError();
290 $this->caches[0]->clearLastError();
304 if ( array_diff( $indexes, [ 0 ] ) &&
$asyncWrites && $method !==
'merge' ) {
310 foreach ( $indexes
as $i ) {
311 $cache = $this->caches[$i];
314 if ( !
$cache->$method( ...$args ) ) {
322 if ( !
$cache->$method( ...$args ) ) {
323 $logger->warning(
"Async $method op failed" );
342 return $this->caches[0]->makeKeyInternal( ...func_get_args() );
345 public function makeKey( $class, $component =
null ) {
346 return $this->caches[0]->makeKey( ...func_get_args() );
350 return $this->caches[0]->makeGlobalKey( ...func_get_args() );
353 protected function doGet( $key, $flags = 0, &$casToken =
null ) {
354 throw new LogicException( __METHOD__ .
': proxy class does not need this method.' );
int[] $cacheIndexes
List of all backing cache indexes.
lock( $key, $timeout=6, $expiry=6, $rclass='')
Acquire an advisory lock on a key string.
doWrite( $indexes, $asyncWrites, $method, array $args)
Apply a write method to the backing caches specified by $indexes (in order)
processing should stop and the error should be shown to the user * false
incrWithInit( $key, $ttl, $value=1, $init=1)
Increase stored value of $key by $value while preserving its TTL.
setMulti(array $data, $exptime=0, $flags=0)
Batch insertion/replace.
getLastError()
Get the "last error" registered; clearLastError() should be called manually.
bool $asyncWrites
Use async secondary writes.
clearLastError()
Clear the "last error" registry.
makeGlobalKey( $class, $component=null)
Make a global cache key.
merge( $key, callable $callback, $exptime=0, $attempts=10, $flags=0)
Merge changes into the existing cache value (possibly creating a new one)
Class representing a cache/ephemeral data store.
changeTTL( $key, $exptime=0, $flags=0)
Change the expiration on a key if it exists.
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
incr( $key, $value=1)
Increase stored value of $key by $value while preserving its TTL.
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
deleteMulti(array $data, $flags=0)
Batch deletion.
unlock( $key)
Release an advisory lock on a key string.
callable null $asyncHandler
const READ_LATEST
Bitfield constants for get()/getMulti()
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
makeKeyInternal( $keyspace, $args)
Construct a cache key.
add( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
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))
deleteObjectsExpiringBefore( $date, $progressCallback=false)
Delete objects expiring before a certain date.
decr( $key, $value=1)
Decrease stored value of $key by $value while preserving its TTL.
__construct( $params)
$params include:
mergeFlagMaps(array $bags)
Merge the flag maps of one or more BagOStuff objects into a "lowest common denominator" map.
makeKey( $class, $component=null)
Make a cache key, scoped to this instance's keyspace.
A cache class that replicates all writes to multiple child caches.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
doGet( $key, $flags=0, &$casToken=null)
unserialize( $serialized)
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
getMulti(array $keys, $flags=0)
Get an associative array containing the item for each of the keys that have items.
usesAsyncWritesGivenFlags( $flags)