2017 © Pedro Peláez
 

library cache

Provides a multi-layered caching abstraction

image

linio/cache

Provides a multi-layered caching abstraction

  • Friday, July 20, 2018
  • by linio
  • Repository
  • 3 Watchers
  • 6 Stars
  • 6,343 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 2 Open issues
  • 33 Versions
  • 9 % Grown

The README.md

Linio Cache

Latest Stable Version License Build Status Scrutinizer Code Quality, (*1)

Linio Cache is yet another component of the Linio Framework. It aims to abstract caching by supporting multiple adapters., (*2)

Install

The recommended way to install Linio Cache is through composer., (*3)

{
    "require": {
        "linio/cache": "dev-master"
    }
}

Tests

To run the test suite, you need install the dependencies via composer, then run PHPUnit., (*4)

$ composer install
$ phpunit

Cache Not Found Keys

It is now possible (v.1.0.9) to cache not found keys in upper level adapters of the adapter stack. The configuration option cache_not_found_keys can be set at the adapter level., (*5)

Note that this option, obviously, does not apply to the last level of the cache hierarchy., (*6)

Usage

<?php

use \Linio\Component\Cache\CacheService;

$container['cache'] = new CacheService([
    'namespace' => 'mx',
    'layers' => [
        0 => [
            'adapter_name' => 'array',
            'adapter_options' => [
                'cache_not_found_keys' => true,
                'encoder' => 'json',
            ],
        ],
        1 => [
            'adapter_name' => 'apc',
            'adapter_options' => [
                'ttl' => 3600,
            ],
        ],
        2 => [
            'adapter_name' => 'redis',
            'adapter_options' => [
                'host' => 'localhost',
                'port' => 6379,
                'ttl' => 0,
                'encoder' => 'serial',
            ],
        ],
    ],
]);

$container->setLogger($container['logger']);

Note that must provide an adapter name and an array of options. Each adapter has different configuration options., (*7)

To start setting data:, (*8)

<?php

$app['cache.service']->set('foo', 'bar');

Methods

get

<?php

    /**
     * @param string $key
     * @return string value
     */
    public function get($key);

    $adapter->get('foo');

getMulti

<?php

     /**
     * @param array $keys
     * @return string[]
     */
    public function getMulti(array $keys);

    $adapter->getMulti(['foo', 'nop']);

set

<?php

     /**
     * @param string $key
     * @param string $value
     * @param ?int $ttl Time To Live; store value in the cache for ttl seconds.
     * This ttl overwrites the configuration ttl of the adapter
     * @return bool
     */
    public function set(string $key, $value, ?int $ttl = null);

    $adapter->set('foo', 'bar');
    $adapter->set('foo', 'bar', 60); // store bar in the cache for 60 seconds

setMulti

<?php

     /**
     * @param array $keys
     * @return bool
     */
    public function setMulti(array $data);

    $adapter->setMulti(['foo' => 'bar', 'fooz' => 'baz']);

delete

<?php

     /**
     * @param string $key
     * @return bool
     */
    public function delete($key);

    $adapter->delete('foo');

deleteMulti

<?php

     /**
     * @param array $keys
     * @return bool
     */
    public function deleteMulti(array $keys);

    $adapter->deleteMulti(['foo', 'fooz']);

contains

<?php

     /**
     * @param string $key
     * @return bool
     */
    public function contains($key);

    $adapter->contains('foo');

flush

<?php

     /**
     * @return bool
     */
    public function flush();

    $adapter->flush();

Providers

array

This cache does not have any persistence between requests., (*9)

Not recommended to be used in production environments., (*10)


apc

Adapter options:, (*11)

  • ttl optional default: 0 (unlimited)
  • cache_not_found_keys optional default: false

Requires APC extension or APCu extension., (*12)


wincache

Adapter options:, (*13)

  • ttl optional default: 0 (unlimited)
  • cache_not_found_keys optional default: false

Requires WinCache extension., (*14)


memcached

Adapter options:, (*15)

  • servers array of memcache servers. format: [[, , ], [, , ], ...]
  • options array of memcache options. format: [ => , => , ...]
  • connection_persistent optional default: false
  • pool_size optional default: 1 (only for persistent connections)
  • ttl optional default: 0 (unlimited)
  • cache_not_found_keys optional default: false

Requires Memcached extension., (*16)


redis

Adapter options:, (*17)

  • host optional default: 127.0.0.1
  • port optional default: 6379
  • database optional default: 0 (int)
  • password optional default: null (no password)
  • connection_persistent optional default: false
  • ttl optional default: 0 (unlimited)
  • cache_not_found_keys optional default: false

More information on the available parameters at the Predis documentation., (*18)


phpredis

Adapter options:, (*19)

  • host optional default: 127.0.0.1
  • port optional default: 6379
  • database optional default: 0 (int)
  • password optional default: null (no password)
  • connection_persistent optional default: false
  • pool_size optional default: 1 (only for persistent connections)
  • timeout optional default: 0 (unlimited)
  • read_timeout optional default: 0 (unlimited)
  • retry_interval optional default: 0 (value in milliseconds)
  • ttl optional default: 0 (unlimited)
  • cache_not_found_keys optional default: false
  • serializer optional default: none
    • none don't serialize data
    • php use built-in serialize/unserialize
    • igbinary use igBinary serialize/unserialize (requires igbinary extension)

More information on the available parameters at the phpredis documentation., (*20)

Requires redis extension., (*21)


mysql

Using PDO., (*22)

Adapter options:, (*23)

  • host
  • port
  • dbname
  • username
  • password
  • table_name
  • ensure_table_created optional default: false
  • cache_not_found_keys optional default: false

The ensure_table_created is used to ensure the cache table exists in the database. This option has a significant performance impact., (*24)

Not recommended to be used in production environments., (*25)


aerospike

Adapter options:, (*26)

  • hosts
  • aerospike_namespace optional default: test
  • persistent optional default: true
  • options optional default: []
  • ttl optional default: 0 (unlimited)
  • cache_not_found_keys optional default: false

For the Aerospike adapter, the aerospike_namespace property will be used as the namespace in Aerospike, and the namespace configuration in the CacheService will be used as the set in Aerospike., (*27)

Requires Aerospike Extension., (*28)


The Versions

20/07 2018

dev-master

9999999-dev

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

25/06 2018

dev-dependabot/composer/phpunit/phpunit-tw-5.0|tw-7.0

dev-dependabot/composer/phpunit/phpunit-tw-5.0|tw-7.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

19/12 2017

2.2.4

2.2.4.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

01/09 2017

2.2.3

2.2.3.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

01/06 2017

2.2.2

2.2.2.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

01/06 2017

2.2.1

2.2.1.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

01/06 2017

2.2.0

2.2.0.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

07/04 2017

2.1.2

2.1.2.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

07/04 2017

2.1.1

2.1.1.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

07/04 2017

2.1.0

2.1.0.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

07/04 2017

2.0.9

2.0.9.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

22/03 2017

2.0.8

2.0.8.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

22/03 2017

2.0.7

2.0.7.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

08/11 2016

2.0.6

2.0.6.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

16/08 2016

2.0.5

2.0.5.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

18/03 2016

2.0.4

2.0.4.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

16/03 2016

2.0.3

2.0.3.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

08/03 2016

2.0.2

2.0.2.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

05/01 2016

2.0.1

2.0.1.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

03/12 2015

2.0.0

2.0.0.0

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

13/10 2015

dev-readme-phpredis-docs

dev-readme-phpredis-docs

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

12/10 2015

dev-feature/phpredis-support

dev-feature/phpredis-support

Provides a multi-layered caching abstraction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

cache redis memcache linio

16/06 2015
15/06 2015
06/04 2015
16/03 2015