MediaWiki master
MediaWiki\Page\CacheKeyHelper Class Reference

Helper class for mapping page value objects to a string key. More...

Static Public Member Functions

static getKeyForPage ( $page)
 Returns a stable key for identifying the given page in a cache.
 

Detailed Description

Helper class for mapping page value objects to a string key.

This logic should not reside in a class like PageStoreRecord or Title, because:

  1. These value object should not contain care about caching in other classes.
  2. We type against interfaces like PageReference and LinkTarget, and for caching to work, all implementations would have to derive cache keys in the exact same way. Otherwise, caches will break when different implementations are passed to the same cache.

Furthermore, the logic for deriving cache keys also should not reside in a service class, because there must only ever be one implementation, it must not depend on configuration, and it may never change.

Since
1.37

Definition at line 32 of file CacheKeyHelper.php.

Member Function Documentation

◆ getKeyForPage()

static MediaWiki\Page\CacheKeyHelper::getKeyForPage ( $page)
static

Returns a stable key for identifying the given page in a cache.

The return value takes into account the page's DB key, namespace and wiki ID or interwiki prefix. It is suitable for use with BagOStuff::makeKey and BagOStuff::makeGlobalKey.

Note
The key that this method returns for a given page should never change. Changing the return value may have sever impact on deployment, as it would cause caches that rely on this method to become effectively "cold" (empty).
Parameters
LinkTarget | PageReference$page
Returns
string A string suitable for identifying the given page. Callers should not attempt to extract information from this value, it should be treated as opaque (but stable).

Definition at line 56 of file CacheKeyHelper.php.

Referenced by MediaWiki\Deferred\HtmlFileCacheUpdate\newFromPages().


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