The Cache module (cache) provides a common API and a centralized place to manage caches.
The module comes with cache managers for the framework ICanBoogie.
You can use any kind of cache with the "cache" module, your manager only has to extends the
CacheManagerBase class or implement the CacheManager interface.
The following properties must also be provided:
- (string)
title: Title of the cache. The title is translated within thecache.titlescope. - (string)
description: Description of the cache. The description is translated within thecache.descriptionscope. - (string)
group: Caches are displayed by groups. The group of the cache can be defined using this property. The group is translated within thecache.groupscope. - (bool)
state: Whether the cache is enabled. - (int|bool)
size_limit: Size limit of the cache, orfalseif not applicable. - (int|bool)
time_limit: Time limit of the entries in the cache, orfalseif not applicable. - (string|null)
config_preview: A preview of the cache configuration, ornullif not applicable. - (string)
editor: The configuration editor, ornullif not applicable.
Note: Because the config_preview and editor properties are seldom used, it is advised to use
getters to return their values:
<?phpuseICanBoogie\Accessor\AccessorTrait;
abstractclass CacheManagerAbstract implementsIcybee\Modules\Cache\CacheManager
{
use AccessorTrait;
protectedfunctionget_config_preview()
{
// …
}
protectedfunctionget_editor()
{
// …
}
}Cache managers are registered on the Icybee\Modules\Cache\CacheCollection::collect event. For
instance, this is how the "views" module registers its cache manager using the hooks
configuration:
<?php// hooks.phpnamespaceIcybee\Modules\Views;
$hooks = Hooks::class . '::';
return [
'events' => [
'Icybee\Modules\Cache\CacheCollection::collect' => $hooks . 'on_cache_collection_collect',
// ...
],
// ...
];Third parties may use the event of class Icybee\Modules\Cache\CacheCollection\CollectEvent to
register their cache manager. The event is fired during the construct of the cache collection.
The following code is an example of how the icybee.views cache is added to the cache collection:
<?phpnamespaceIcybee\Modules\Views;
useIcybee\Modules\Cache\CacheCollectionasCacheCollection;
class Hooks
{
// …staticpublicfunctionon_cache_collection_collect(CacheCollection\CollectEvent$event, CacheCollection$collection)
{
$event->collection['icybee.views'] = newViewCacheManager;
}
// …
}The get_caches getter is added to instances of the ICanBoogie\Application class, it returns
the cache collection.
<?php/* @var \ICanBoogie\Application $app */$app->caches['core.modules']->clear();Cache operations require the cache identifier to be defined as key of the operation. For instance,
to clear the core.modules cache the operation POST /api/cache/core.modules/clear is used.
Clears the specified cache.
Configures the specified cache.
Disables the specified cache.
Returns the configuration editor.
The editor is obtained through the editor property of the cache.
Enables the specified cache.
The cache is cleared before it is enabled.
Returns the usage (memory, files) of the specified cache.
The caches of ICanBoogie are cleared when modules are activated.
The caches of ICanBoogie are cleared when modules are deactivated.
The package requires PHP 5.6 or later.
The recommended way to install this package is through Composer:
$ composer require icybee/module-cache
The package is available on GitHub, its repository can be cloned with the following command line:
$ git clone https://github.com/Icybee/module-cache.git
The package is documented as part of the Icybee CMS
documentation. The documentation for the package and its
dependencies can be generated with the make doc command. The documentation is generated in
the docs directory using ApiGen. The package directory can later by
cleaned with the make clean command.
The module is licensed under the New BSD License - See the LICENSE file for details.