itrnka/ha-apcu-middleware

APCu cache middleware for ha framework. This is a proxy to PHP APCu extension.

v1.0.1 2017-11-15 00:00 UTC

This package is not auto-updated.

Last update: 2024-11-10 06:07:04 UTC


README

APCu cache middleware for ha framework. This is a proxy to PHP APCu extension. Driver implements cache interface ha\Middleware\Cache\Cache from ha framework. So it can be used as a cache driver.

Installation

Installation is available via composer:

composer require itrnka/ha-apcu-middleware

Requirements

This package is based on ha framework. Composer installs ha framework if it is not already installed. APCu php module is also required.

Configuration

Required configuration keys:

  • name: by ha framework requirements
  • keyPrefix: string prefix for cache keys in your application
  • defaultTTL: int default TTL value (must be >= 0)

Add your configuration to the configuration file in ha framework according to this example:

Note: only single instance can be used in your application, class has pseudo singleton protection.

$cfg['middleware'] = [

    // ...

    // APCu cahce
    [
        ha\Middleware\Cache\APCu\APCu::class,
        [
            'name' => 'apc',
            'keyPrefix' => 'someUniqueKeyForAppInYourMachine',
            'defaultTTL' => 0,
        ]
    ],

    // ...

];

Then the driver will be available as follows:

// middleware instance
$apc = main()->middleware->apc;

// example call:
$value = main()->middleware->apc->get('myValue', null);