Skip to content
comhon-project edited this page Dec 3, 2020 · 6 revisions

Table of content

  1. Preamble
  2. Handlers
    1. File system
    2. Memcached
  3. Reset cache

Preamble

To increase loading config and model speed, you can define a cache. To use cache, you have to specify which cache you want in configuration file under cache_settings property. cache_settings value must be a string, it must begin with the cache handler name followed by a colon, followed by specific handler informations. There are two cache handlers available explained in following chapters.

File system

File system cache permit to store cached config and models in a specific directory. The handler name is directory. You must specify the directory path.
example:

directory:/my/absolute/path/to/folder

you may define a relative path to config file directory, example:

directory:./my/relative/path/to/folder

Memcached

Memcached cache permit to store cached config and models using memcached. The handler name is memcached. You must specify connection informations, host and port separated by semicolon.
example:

memcached:host=127.0.0.1;port=11211

You may configure memcache instance. To do so, you can retrieve instance from ModelManager.

$cacheHandler = ModelManager::getInstance()->getCacheHandler();
$memcached = $cacheHandler->getMemCachedObject();

// examples
$memcached->addServer('mem1.domain.com', 11211);
$memcached->setOption(Memcached::OPT_HASH, Memcached::HASH_MURMUR);

Reset cache

The cache must be reset if you have maid changes on config or manifests (and serialization manifest) otherwise modifications will not be taken in account. The cache must be reset if you update Comhon version.
Warning!!! for memcached handler, reset cache will execute a flush and all existing items will be invalidated immediately.

To reset cache there are two way :

  • using ModelManager
$cacheHandler = ModelManager::getInstance()->getCacheHandler()->reset();
  • using available CLI script. To call script from your project folder where vendor folder might be found, type following line :
> php vendor/comhon-project/comhon/src/Comhon/Executable/ResetCache.php

Clone this wiki locally