2017 © Pedro Peláez
 

icanboogie-module module-cache

Provides a common API and a centralized place to manage caches.

image

icybee/module-cache

Provides a common API and a centralized place to manage caches.

  • Saturday, June 24, 2017
  • by olvlvl
  • Repository
  • 1 Watchers
  • 0 Stars
  • 701 Installations
  • PHP
  • 5 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Cache

The Cache module (cache) provides a common API and a centralized place to manage caches., (*1)

The module comes with cache managers for the framework ICanBoogie., (*2)

Cache managers

Creating your own cache manager

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., (*3)

The following properties must also be provided:, (*4)

  • (string) title: Title of the cache. The title is translated within the cache.title scope.
  • (string) description: Description of the cache. The description is translated within the cache.description scope.
  • (string) group: Caches are displayed by groups. The group of the cache can be defined using this property. The group is translated within the cache.group scope.
  • (bool) state: Whether the cache is enabled.
  • (int|bool) size_limit: Size limit of the cache, or false if not applicable.
  • (int|bool) time_limit: Time limit of the entries in the cache, or false if not applicable.
  • (string|null) config_preview: A preview of the cache configuration, or null if not applicable.
  • (string) editor: The configuration editor, or null if not applicable.

Note: Because the config_preview and editor properties are seldom used, it is advised to use getters to return their values:, (*5)

<?php

use ICanBoogie\Accessor\AccessorTrait;

abstract class CacheManagerAbstract implements Icybee\Modules\Cache\CacheManager
{
    use AccessorTrait;

    protected function get_config_preview()
    {
        // …
    }

    protected function get_editor()
    {
        // …
    }
}

Registering your cache manager

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:, (*6)

<?php

// hooks.php

namespace Icybee\Modules\Views;

$hooks = Hooks::class . '::';

return [
    'events' => [
        'Icybee\Modules\Cache\CacheCollection::collect' => $hooks . 'on_cache_collection_collect',
        // ...
    ],
    // ...
];

Events

Icybee\Modules\Cache\CacheCollection::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., (*7)

The following code is an example of how the icybee.views cache is added to the cache collection:, (*8)

<?php

namespace Icybee\Modules\Views;

use Icybee\Modules\Cache\CacheCollection as CacheCollection;

class Hooks
{
    // …

    static public function on_cache_collection_collect(CacheCollection\CollectEvent $event, CacheCollection $collection)
    {
        $event->collection['icybee.views'] = new ViewCacheManager;
    }

    // …
}

Prototype methods

ICanBoogie\Application::get_caches

The get_caches getter is added to instances of the ICanBoogie\Application class, it returns the cache collection., (*9)

<?php

/* @var \ICanBoogie\Application $app */

$app->caches['core.modules']->clear();

Operations

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., (*10)

Icybee\Modules\Cache\ClearOperation

Clears the specified cache., (*11)

Icybee\Modules\Cache\ConfigureOperation

Configures the specified cache., (*12)

Icybee\Modules\Cache\DisableOperation

Disables the specified cache., (*13)

Icybee\Modules\Cache\EditorOperation

Returns the configuration editor., (*14)

The editor is obtained through the editor property of the cache., (*15)

Icybee\Modules\Cache\EnableOperation

Enables the specified cache., (*16)

The cache is cleared before it is enabled., (*17)

Icybee\Modules\Cache\StatOperation

Returns the usage (memory, files) of the specified cache., (*18)

Event hooks

Icybee\Modules\Modules\ActivateOperation::process

The caches of ICanBoogie are cleared when modules are activated., (*19)

Icybee\Modules\Modules\DeactivateOperation:process

The caches of ICanBoogie are cleared when modules are deactivated., (*20)


Requirement

The package requires PHP 5.6 or later., (*21)

Installation

The recommended way to install this package is through Composer:, (*22)

$ composer require icybee/module-cache

Cloning the repository

The package is available on GitHub, its repository can be cloned with the following command line:, (*23)

$ git clone https://github.com/Icybee/module-cache.git

Documentation

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., (*24)

License

The module is licensed under the New BSD License - See the LICENSE file for details., (*25)

The Versions

24/06 2017

4.0.x-dev

4.0.9999999.9999999-dev

Provides a common API and a centralized place to manage caches.

  Sources   Download

BSD-3-Clause

The Requires

 

cache

24/05 2016

3.0.x-dev

3.0.9999999.9999999-dev

Provides a common API and a centralized place to manage caches.

  Sources   Download

BSD-3-Clause

The Requires

 

cache

24/05 2016

v3.0.0

3.0.0.0

Provides a common API and a centralized place to manage caches.

  Sources   Download

BSD-3-Clause

The Requires

 

cache

25/07 2015

v2.1.0

2.1.0.0

Provides a common API and a centralized place to manage caches.

  Sources   Download

BSD-3-Clause

The Requires

 

cache

14/03 2015

v2.0.2

2.0.2.0

Provides a common API and a centralized place to manage caches.

  Sources   Download

BSD-3-Clause

The Requires

 

cache

30/10 2014

v2.0.1

2.0.1.0

Provides a common API and a centralized place to manage caches.

  Sources   Download

BSD-3-Clause

The Requires

 

cache

27/10 2014

v2.0.0

2.0.0.0

Provides a common API and a centralized place to manage caches.

  Sources   Download

BSD-3-Clause

The Requires

 

cache