m6web/apcu-bundle

There is no license information available for the latest version (v3.0.0) of this package.

Provide APCu support

Installs: 127 003

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 49

Forks: 1

Open Issues: 1

Type:symfony-bundle

v3.0.0 2022-08-10 07:56 UTC

This package is auto-updated.

Last update: 2024-11-10 12:54:27 UTC


README

Provide APCu support, see PECL/APCu.

Installation

Via Composer :

"require": {
    "m6web/apcu-bundle" : "^1.4"
}

Also require the PECL extension APCu :

# pecl install -f apcu

Don't forget to enable the extension in your php.ini.

NB: due to an update in APCu API, from ApcuBundle v1.1.1, you must install APCu v4.0.7 or higher

Configuration

The main configuration key is m6web_apcu. Each subkey defines a new Apcu cache service. These services are named m6web_apcu + subkey. For each service, several parameters can be set :

  • namespace (string, optional) : Empty by default. Namespace for all keys stored in APCu cache via this instance.
  • ttl (integer, optionnal) : 3600 (seconds) by default. Define the default TTL used when no TTL is given to store data.
  • class (string, optionnal) : You can override the default cache class. It should extends M6Web\Bundle\ApcuBundle\Apcu\Apcu.

Example

m6web_apcu:
    myCache:
        namespace: 6play-api-applaunch
        ttl: 3600
    otherCache: ~

Usage

$cache = $container->get('m6web_apcu.myCache');
$key   = 'myCacheKey';

var_dump($cache->exists($key)); // boolean, false

$cache->store($key, 'Hello', 3600)

var_dump($cache->exists($key)); // boolean, true
var_dump($cache->fetch($key)); // string, Hello

$cache->delete($key);

var_dump($cache->exists($key)); // boolean, false
var_dump($cache->fetch($key)); // bolean, false

Tests

If you wish to run Bundle tests, you must enable APCu in CLI environment by defining apc.enable_cli option to 1.

Then you can run the tests :

$ ./vendor/bin/phpunit tests