MediaWiki  1.33.0
CachedBagOStuff.php
Go to the documentation of this file.
1 <?php
39  protected $backend;
40 
45  function __construct( BagOStuff $backend, $params = [] ) {
46  unset( $params['reportDupes'] ); // useless here
47 
48  parent::__construct( $params );
49 
50  $this->backend = $backend;
51  $this->attrMap = $backend->attrMap;
52  }
53 
54  public function get( $key, $flags = 0 ) {
55  $ret = parent::get( $key, $flags );
56  if ( $ret === false && !$this->hasKey( $key ) ) {
57  $ret = $this->backend->get( $key, $flags );
58  $this->set( $key, $ret, 0, self::WRITE_CACHE_ONLY );
59  }
60  return $ret;
61  }
62 
63  public function set( $key, $value, $exptime = 0, $flags = 0 ) {
64  parent::set( $key, $value, $exptime, $flags );
65  if ( !( $flags & self::WRITE_CACHE_ONLY ) ) {
66  $this->backend->set( $key, $value, $exptime, $flags & ~self::WRITE_CACHE_ONLY );
67  }
68  return true;
69  }
70 
71  public function delete( $key, $flags = 0 ) {
72  parent::delete( $key, $flags );
73  if ( !( $flags & self::WRITE_CACHE_ONLY ) ) {
74  $this->backend->delete( $key );
75  }
76 
77  return true;
78  }
79 
80  public function setDebug( $bool ) {
81  parent::setDebug( $bool );
82  $this->backend->setDebug( $bool );
83  }
84 
85  public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) {
86  parent::deleteObjectsExpiringBefore( $date, $progressCallback );
87  return $this->backend->deleteObjectsExpiringBefore( $date, $progressCallback );
88  }
89 
90  public function makeKeyInternal( $keyspace, $args ) {
91  return $this->backend->makeKeyInternal( ...func_get_args() );
92  }
93 
94  public function makeKey( $class, $component = null ) {
95  return $this->backend->makeKey( ...func_get_args() );
96  }
97 
98  public function makeGlobalKey( $class, $component = null ) {
99  return $this->backend->makeGlobalKey( ...func_get_args() );
100  }
101 
102  // These just call the backend (tested elsewhere)
103  // @codeCoverageIgnoreStart
104 
105  public function add( $key, $value, $exptime = 0, $flags = 0 ) {
106  if ( $this->get( $key ) === false ) {
107  return $this->set( $key, $value, $exptime, $flags );
108  }
109 
110  return false; // key already set
111  }
112 
113  public function incr( $key, $value = 1 ) {
114  $n = $this->backend->incr( $key, $value );
115  parent::delete( $key );
116 
117  return $n;
118  }
119 
120  public function lock( $key, $timeout = 6, $expiry = 6, $rclass = '' ) {
121  return $this->backend->lock( $key, $timeout, $expiry, $rclass );
122  }
123 
124  public function unlock( $key ) {
125  return $this->backend->unlock( $key );
126  }
127 
128  public function getLastError() {
129  return $this->backend->getLastError();
130  }
131 
132  public function clearLastError() {
133  return $this->backend->clearLastError();
134  }
135 
136  // @codeCoverageIgnoreEnd
137 }
CachedBagOStuff\clearLastError
clearLastError()
Clear the "last error" registry.
Definition: CachedBagOStuff.php:132
HashBagOStuff
Simple store for keeping values in an associative array for the current process.
Definition: HashBagOStuff.php:31
CachedBagOStuff\unlock
unlock( $key)
Release an advisory lock on a key string.
Definition: CachedBagOStuff.php:124
CachedBagOStuff\getLastError
getLastError()
Get the "last error" registered; clearLastError() should be called manually.
Definition: CachedBagOStuff.php:128
CachedBagOStuff\makeKey
makeKey( $class, $component=null)
Make a cache key, scoped to this instance's keyspace.
Definition: CachedBagOStuff.php:94
$params
$params
Definition: styleTest.css.php:44
BagOStuff
Class representing a cache/ephemeral data store.
Definition: BagOStuff.php:58
HashBagOStuff\hasKey
hasKey( $key)
Does this bag have a non-null value for the given key?
Definition: HashBagOStuff.php:151
CachedBagOStuff\__construct
__construct(BagOStuff $backend, $params=[])
Definition: CachedBagOStuff.php:45
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
CachedBagOStuff\setDebug
setDebug( $bool)
Definition: CachedBagOStuff.php:80
CachedBagOStuff\$backend
BagOStuff $backend
Definition: CachedBagOStuff.php:39
CachedBagOStuff\deleteObjectsExpiringBefore
deleteObjectsExpiringBefore( $date, $progressCallback=false)
Delete all objects expiring before a certain date.
Definition: CachedBagOStuff.php:85
CachedBagOStuff\makeKeyInternal
makeKeyInternal( $keyspace, $args)
Construct a cache key.
Definition: CachedBagOStuff.php:90
CachedBagOStuff\add
add( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
Definition: CachedBagOStuff.php:105
$value
$value
Definition: styleTest.css.php:49
CachedBagOStuff
Wrapper around a BagOStuff that caches data in memory.
Definition: CachedBagOStuff.php:37
$ret
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
Definition: hooks.txt:1985
$args
if( $line===false) $args
Definition: cdb.php:64
CachedBagOStuff\incr
incr( $key, $value=1)
Increase stored value of $key by $value while preserving its TTL.
Definition: CachedBagOStuff.php:113
CachedBagOStuff\makeGlobalKey
makeGlobalKey( $class, $component=null)
Make a global cache key.
Definition: CachedBagOStuff.php:98
BagOStuff\$keyspace
string $keyspace
Definition: BagOStuff.php:64
CachedBagOStuff\lock
lock( $key, $timeout=6, $expiry=6, $rclass='')
Acquire an advisory lock on a key string.
Definition: CachedBagOStuff.php:120
BagOStuff\WRITE_CACHE_ONLY
const WRITE_CACHE_ONLY
Definition: BagOStuff.php:95