m6web / apcu-bundle
Provide APCu support
Installs: 127 003
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 49
Forks: 1
Open Issues: 1
Type:symfony-bundle
Requires
- php: ^8.0
- ext-apcu: >=4.0.7
Requires (Dev)
- guzzle/cache: ^3.9.2
- m6web/guzzle-http-bundle: ^4.0 || ^5.0
- m6web/php-cs-fixer-config: ^2.0
- phpunit/phpunit: ^9.5
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 extendsM6Web\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