MediaWiki REL1_35
WANObjectCacheReaper Class Reference

Class for scanning through chronological, log-structured data or change logs and locally purging cache keys related to entities that appear in this data. More...

Inheritance diagram for WANObjectCacheReaper:
Collaboration diagram for WANObjectCacheReaper:

Public Member Functions

 __construct (WANObjectCache $cache, BagOStuff $store, callable $logCallback, callable $keyCallback, array $params)
 
 getState ()
 
 invoke ( $n=100)
 Check and reap stale keys based on a chunk of events.
 
 setLogger (LoggerInterface $logger)
 

Protected Attributes

WANObjectCache $cache
 
string $channel
 
int $initialStartWindow
 
callable $keyListCallback
 
callable $logChunkCallback
 
LoggerInterface $logger
 
BagOStuff $store
 

Detailed Description

Class for scanning through chronological, log-structured data or change logs and locally purging cache keys related to entities that appear in this data.

This is useful for repairing cache when purges are missed by using a reliable stream, such as Kafka or a replicated MySQL table. Purge loss between datacenters is expected to be more common than within them.

Since
1.28

Definition at line 37 of file WANObjectCacheReaper.php.

Constructor & Destructor Documentation

◆ __construct()

WANObjectCacheReaper::__construct ( WANObjectCache  $cache,
BagOStuff  $store,
callable  $logCallback,
callable  $keyCallback,
array  $params 
)
Parameters
WANObjectCache$cacheCache to reap bad keys from
BagOStuff$storeCache to store positions use for locking
callable$logCallbackCallback taking arguments:
  • The starting position as a UNIX timestamp
  • The starting unique ID used for breaking timestamp collisions or null
  • The ending position as a UNIX timestamp
  • The maximum number of results to return It returns a list of maps of (key: cache key, pos: UNIX timestamp, id: unique ID) for each key affected, with the corrosponding event timestamp/ID information. The events should be in ascending order, by (timestamp,id).
callable$keyCallbackCallback taking arguments:
  • The WANObjectCache instance
  • An object from the event log It should return a list of WAN cache keys. The callback must fully duck-type test the object, since can be any model class.
array$paramsAdditional options:
  • channel: the name of the update event stream.
  • initialStartWindow: seconds back in time to start if the position is lost. Default: 1 hour.
  • logger: an SPL monolog instance [optional]

Definition at line 76 of file WANObjectCacheReaper.php.

References $cache, and $store.

Member Function Documentation

◆ getState()

WANObjectCacheReaper::getState ( )
Returns
array|bool Returns (pos, id) map or false if not set

Definition at line 194 of file WANObjectCacheReaper.php.

◆ invoke()

WANObjectCacheReaper::invoke (   $n = 100)
final

Check and reap stale keys based on a chunk of events.

Parameters
int$nNumber of events
Returns
int Number of keys checked

Definition at line 108 of file WANObjectCacheReaper.php.

References $initialStartWindow, and $keys.

◆ setLogger()

WANObjectCacheReaper::setLogger ( LoggerInterface  $logger)

Definition at line 98 of file WANObjectCacheReaper.php.

References $logger.

Member Data Documentation

◆ $cache

WANObjectCache WANObjectCacheReaper::$cache
protected

Definition at line 39 of file WANObjectCacheReaper.php.

Referenced by __construct().

◆ $channel

string WANObjectCacheReaper::$channel
protected

Definition at line 50 of file WANObjectCacheReaper.php.

◆ $initialStartWindow

int WANObjectCacheReaper::$initialStartWindow
protected

Definition at line 52 of file WANObjectCacheReaper.php.

Referenced by invoke().

◆ $keyListCallback

callable WANObjectCacheReaper::$keyListCallback
protected

Definition at line 45 of file WANObjectCacheReaper.php.

◆ $logChunkCallback

callable WANObjectCacheReaper::$logChunkCallback
protected

Definition at line 43 of file WANObjectCacheReaper.php.

◆ $logger

LoggerInterface WANObjectCacheReaper::$logger
protected

Definition at line 47 of file WANObjectCacheReaper.php.

Referenced by setLogger().

◆ $store

BagOStuff WANObjectCacheReaper::$store
protected

Definition at line 41 of file WANObjectCacheReaper.php.

Referenced by __construct().


The documentation for this class was generated from the following file: