sparq-php/cache

Cache made simple

1.1.5 2020-08-20 11:15 UTC

This package is auto-updated.

Last update: 2024-04-21 02:24:02 UTC


README

pipeline status Latest Stable Version coverage report Total Downloads License

A simple to use cache class.

Installation and Autoloading

The recommended method of installing is via Composer.

Run the following command from your project root:

$ composer require sparq-php/cache

Objectives

  • Simple to use cache
  • Easy integration with other packages/frameworks
  • Fast and low footprint

Usage

require_once __DIR__ . "/vendor/autoload.php";

use RedisClient\RedisClient;
use Sparq\Cache\AbstractCache;

class Foo extends AbstractCache
{
	public function events()
    {
        return [
            'before.get' => function ($key) {
            	if ('myObject' === $key) {
                    $this->set($key, (object) [
                        'some' => 'value',
                    ]);
                }

                if ('myArray' === $key) {
                    $this->set($key, [
                        'some' => 'value',
                    ]);
                }

                if ('some' === $key) {
                    $this->set($key, 'value');
                }
            }
		];
	}
}

$Foo = new Foo();
$Foo->register('memory', new \Sparq\Cache\Adapter\Memory(), 100);
$Foo->register('redis', new \Sparq\Cache\Adapter\RedisExtension(new Redis()), 50);
$Foo->register('redis', new \Sparq\Cache\Adapter\RedisPhpClient(new RedisClient()), 40);

echo $Foo->myObject->some;
echo $Foo->myArray['some'];
echo $Foo->some;