MediaWiki master
MediaWiki\Language\LCStoreStaticArray Class Reference

Localisation cache storage based on PHP files and static arrays. More...

Inherits MediaWiki\Language\LCStore.

Collaboration diagram for MediaWiki\Language\LCStoreStaticArray:

Public Member Functions

 __construct (array $conf=[])
 
 finishWrite ()
 Finish a cache write transaction.
 
 get ( $code, $key)
 Get a value.
Parameters
string$codeLanguage code
string$keyCache key

 
 lateFallback ()
 Can this cache type delay fallback lookups to read time?Returning true will cause the fallbacks to be skipped when recaching data, and instead performed via multiple reads if necessary at runtime.This is best when performing lookups is extremely low-cost, such as LCStoreStaticArray with the lateFallback option.When reading from disk or network, trading off the space for fewer lookups may still be a win. Returning false will keep the classic behavior of pre-filling all the fallback chains for each language.
 
 set ( $key, $value)
 Set a key to a given value.startWrite() must be called before this is called, and finishWrite() must be called after.
Parameters
string$key
mixed$value

 
 startWrite ( $code)
 Start a cache write transaction.
Parameters
string$codeLanguage code

 

Static Public Member Functions

static decode ( $encoded)
 Decode something that was encoded with 'encode'.
 
static encode ( $value)
 Encodes a value into an array format.
 

Protected Member Functions

 atomicWrite (string $fileName, array $data)
 
 getMessageKey (string $key)
 

Detailed Description

Localisation cache storage based on PHP files and static arrays.

This is meant to leverage the PHP opcache and may require increasing memory sizes on a production site that handles many languages routinely.

These php.ini settings are sufficient for some local testing, but would be rather too small for Wikimedia production which has many localised extensions installed.

  • opcache.memory_consumption=1024
  • opcache.interned_strings_buffer=256

As of MediaWiki 1.46, this cache backend does two important things differently from the CDB backend:

  • Late fallback: tells LocalisationCache to do late fallback/merge logic at read time, reducing redundant data in the .l10n.php files for a slight, hard to measure runtime cost in looking up a few more arrays.

    This gives a massive reduction in both disk usage and opcode cache usage versus pre-merging all the fallbacks: strings are already deduplicated in the opcache's string interning but const array hashmap data is not!

  • Re-assembly of split keys: the messages array is reconstructed to avoid duplicating the prefix 'messages:' thousands of times and make the key list cheap to load.

Additionally, LCStoreStaticArray silently drops the 'preload' and 'preloadMessages' data duplication in each language, as it's cheap to query the messages individually.

The resulting cache files are about ~80% smaller than under 1.45 due to the drop in redundant data, and compress very well for delta copies.

Older cached data from before 1.46 is backwards-compatible on read.

Since
1.26

Definition at line 55 of file LCStoreStaticArray.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Language\LCStoreStaticArray::__construct ( array $conf = [])

Definition at line 72 of file LCStoreStaticArray.php.

Member Function Documentation

◆ atomicWrite()

MediaWiki\Language\LCStoreStaticArray::atomicWrite ( string $fileName,
array $data )
protected

◆ decode()

static MediaWiki\Language\LCStoreStaticArray::decode ( $encoded)
static

Decode something that was encoded with 'encode'.

Parameters
mixed$encoded
Returns
array|mixed
Exceptions
RuntimeException

Definition at line 163 of file LCStoreStaticArray.php.

◆ encode()

static MediaWiki\Language\LCStoreStaticArray::encode ( $value)
static

Encodes a value into an array format.

Parameters
mixed$value
Returns
array|mixed
Exceptions
RuntimeException

Definition at line 136 of file LCStoreStaticArray.php.

Referenced by MediaWiki\Language\LCStoreStaticArray\set().

◆ finishWrite()

MediaWiki\Language\LCStoreStaticArray::finishWrite ( )

Finish a cache write transaction.

Implements MediaWiki\Language\LCStore.

Definition at line 186 of file LCStoreStaticArray.php.

References MediaWiki\Language\LCStoreStaticArray\atomicWrite().

◆ get()

MediaWiki\Language\LCStoreStaticArray::get ( $code,
$key )

Get a value.

Parameters
string$codeLanguage code
string$keyCache key

Implements MediaWiki\Language\LCStore.

Definition at line 217 of file LCStoreStaticArray.php.

◆ getMessageKey()

MediaWiki\Language\LCStoreStaticArray::getMessageKey ( string $key)
protected

Definition at line 209 of file LCStoreStaticArray.php.

◆ lateFallback()

MediaWiki\Language\LCStoreStaticArray::lateFallback ( )

Can this cache type delay fallback lookups to read time?Returning true will cause the fallbacks to be skipped when recaching data, and instead performed via multiple reads if necessary at runtime.This is best when performing lookups is extremely low-cost, such as LCStoreStaticArray with the lateFallback option.When reading from disk or network, trading off the space for fewer lookups may still be a win. Returning false will keep the classic behavior of pre-filling all the fallback chains for each language.

Implements MediaWiki\Language\LCStore.

Definition at line 261 of file LCStoreStaticArray.php.

◆ set()

MediaWiki\Language\LCStoreStaticArray::set ( $key,
$value )

Set a key to a given value.startWrite() must be called before this is called, and finishWrite() must be called after.

Parameters
string$key
mixed$value

Implements MediaWiki\Language\LCStore.

Definition at line 91 of file LCStoreStaticArray.php.

References MediaWiki\Language\LCStoreStaticArray\encode().

◆ startWrite()

MediaWiki\Language\LCStoreStaticArray::startWrite ( $code)

Start a cache write transaction.

Parameters
string$codeLanguage code

Implements MediaWiki\Language\LCStore.

Definition at line 77 of file LCStoreStaticArray.php.

References wfMkdirParents().


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