Development Wiki

PhpBB3.1/RFC/Cache Refactoring

From phpBB Development Wiki

Revision as of 08:50, 12 July 2011 by Igorw (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Refactoring the cache system to be more flexible, testable and cleaner.


The current cache system is a mess. The cache modules declare a single 'acm' class, which is then extended by the 'cache' class, adding methods to retrieve and cache certain data. 'acm' is a non-descriptive name which does not seem to be defined.

By refactoring we can make it possible to test different cache implementations, and in theory use different ones for different things. We can make code that depends on cache cleaner, by allowing a driver to be injected.


We encourage passing the cache driver into new classes that perform caching instead of using the global cache service ($cache).


The cache service acts as a container and wrapper for the cache driver and adds methods for retrieving specific data, such as smilies. The main purpose is to provide backward-compatibility. In most cases you should use the driver directly instead, you can do that by calling:

$driver $cache->get_driver();


A driver must implement the phpbb_cache_driver_interface. The only methods you will ever need are:

Get a value from the cache

$value $driver->get('key');

Store something in the cache for one hour


Purge the cache entirely



Each driver has it's own class name and extends a common base class. 'cache' is renamed to 'phpbb_cache_service' and no longer extends the driver. Instead it takes a driver as an argument and uses __call to remain backward-compatible with old code.

It makes use of autoloading.


The cache drivers still do way more than they should (database-related things), but it's a move in the right direction.