Help:LuaCache

LuaCache is an extension that exposes MediaWiki's ObjectCache through a Lua interface, which can be used to store data between requests.

Applications
LuaCache has two main applications: sitewide storage for results of expensive queries, and mitigation of performance issues with modules used on a very large number of pages.

Query caching
LuaCache can be used to cache the results of expensive DPL or Cargo queries, as it will be faster to access the cache than to perform the query again. However, LuaCache is slower than VariablesLua, so a fallback chain might look like: local variable → VariablesLua → LuaCache → expensive query.

Link table thinning
When a data module is used on a page, any change to the data module will require a re-evaluation of that page. When a data module is used on a large number of pages, has to be frequently updated, but most updates only affect a small subset of pages using the data, the result is that the wiki has to regularly perform useless re-evaluation of pages that would not be changed. Using LuaCache to store the data may cause issues typical to caching (requiring pages to be purged or null-edited), but is likely to significantly thin the number of pages the engine believes are "dependent" on the data module. (This number is also known as the number of "transclusions" listed on Special:WhatLinksHere for that page.) As a case of LuaCache use from Leaguepedia, the transclusions count for a data module dropped from approximately 100 thousand pages to 7 pages.

Cache object
To access the object cache, the cache object must be acquired first. This can be done as follows:

cache.get
Returns the value stored in the cache under the given (string) key.

If there is no value stored under the given key,  is returned.

cache.set
Stores the given value in the cache under the given (string) key. Optionally, an exptime (expiration time) in seconds may be specified. Returns  if the value is successfully stored,   otherwise.

cache.getMulti
Retrieves the values stored under the keys given in the supplied array of strings and then constructs and returns a table of the values associated with their respective keys.

cache.setMulti
Accepts a table of data and stores the value in each row in the cache under its respective key. Optionally, an exptime (expiration time) in seconds may be specified, which will be applied to each cache entry.

cache.delete
Removes the cache entry identified by the given (string) key.

Example
produces:

cache.get('sample.singleTest') (nil) cache.set returned true cache.get('sample.singleTest') Hello: World Name: Alyanah Counter: 0

cache.set returned true cache.setMulti returned true When: tomorrow What: 김치찌개 cache.delete returned true sample.multiTest.3 = When: yesterday What: 순두부찌개 sample.multiTest.1 = When: now What: 불고기