2017 © Pedro Peláez
 

library cache

Provides an cache interface for several adapters Apc, Apcu, File, Mongo, Memcache, Memcached, Mysql, Mongo, Redis is supported. New adapters is comming!

image

comporu/cache

Provides an cache interface for several adapters Apc, Apcu, File, Mongo, Memcache, Memcached, Mysql, Mongo, Redis is supported. New adapters is comming!

  • Tuesday, February 2, 2016
  • by comporu
  • Repository
  • 1 Watchers
  • 0 Stars
  • 68 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 38 Forks
  • 0 Open issues
  • 20 Versions
  • 0 % Grown

The README.md

Cache SensioLabsInsight

A simple cache library. Implements different adapters that you can use and change easily by a manager or similar., (*1)

Latest version ![Latest version][ico-pre-release] Software License ![Build Status][ico-travis] Coverage Status ![Quality Score][ico-code-quality] Sensiolabs Insight ![Total Downloads][ico-downloads] Today Downloads [![Gitter][ico-gitter]][link-gitter], (*2)

Installation

With Composer

It is best installed it through packagist by including desarrolla2/cache in your project composer.json require:, (*3)

``` json "require": { // ... "desarrolla2/cache": "~2.0" }, (*4)


### Without Composer You can also download it from [Github] (https://github.com/desarrolla2/Cache), but no autoloader is provided so you'll need to register it with your own PSR-0 compatible autoloader. ## Usage ``` php <?php use Desarrolla2\Cache\Cache; use Desarrolla2\Cache\Adapter\NotCache; $cache = new Cache(new NotCache()); $cache->set('key', 'myKeyValue', 3600); // later ... echo $cache->get('key');

Adapters

Apcu

Use it if you will you have APC cache available in your system., (*5)

``` php <?php, (*6)

use Desarrolla2\Cache\Cache; use Desarrolla2\Cache\Adapter\Apcu;, (*7)

$adapter = new Apcu(); $adapter->setOption('ttl', 3600); $cache = new Cache($adapter);, (*8)


### File Use it if you will you have dont have other cache system available in your system or if you like to do your code more portable. ``` php <?php use Desarrolla2\Cache\Cache; use Desarrolla2\Cache\Adapter\File; $cacheDir = '/tmp'; $adapter = new File($cacheDir); $adapter->setOption('ttl', 3600); $cache = new Cache($adapter);

Memcache

Use it if you will you have mencache available in your system., (*9)

``` php <?php, (*10)

use Desarrolla2\Cache\Cache; use Desarrolla2\Cache\Adapter\Memcache;, (*11)

$adapter = new Memcache(); $cache = new Cache($adapter);, (*12)


You can config your connection before ``` php <?php use Desarrolla2\Cache\Cache; use Desarrolla2\Cache\Adapter\Memcache; use \Memcache as Backend $backend = new Backend(); // configure it here $cache = new Cache(new Memcache($backend));

Memcached

Is the same like mencache adapter., (*13)

Memory

This is the fastest cache type, since the elements are stored in memory. Cache Memory such is very volatile and is removed when the process terminates. Also it is not shared between different processes., (*14)

Memory cache have a option "limit", that limit the max items in cache., (*15)

``` php <?php, (*16)

use Desarrolla2\Cache\Cache; use Desarrolla2\Cache\Adapter\Memory;, (*17)

$adapter = new Memory(); $adapter->setOption('ttl', 3600); $adapter->setOption('limit', 200); $cache = new Cache($adapter);, (*18)


### Mongo Use it to store the cache in a Mongo database. Requires the [(legacy) mongo extension](http://php.net/mongo) or the [mongodb/mongodb](https://github.com/mongodb/mongo-php-library) library. You may pass either a database or collection object to the constructor. If a database object is passed, the `items` collection within that DB is used. ``` php <?php use Desarrolla2\Cache\Cache; use Desarrolla2\Cache\Adapter\Mongo; $client = new MongoClient($dsn); $database = $client->selectDatabase($dbname); $adapter = new Mongo($database); $adapter->setOption('ttl', 3600); $cache = new Cache($adapter);

``` php <?php, (*19)

use Desarrolla2\Cache\Cache; use Desarrolla2\Cache\Adapter\Mongo;, (*20)

$client = new MongoClient($dsn); $database = $client->selectDatabase($dbName); $collection = $database->selectCollection($collectionName);, (*21)

$adapter = new Mongo($collection); $adapter->setOption('ttl', 3600); $cache = new Cache($adapter);, (*22)


_Note that expired cache items aren't automatically deleted. To keep your database clean, you should create a [ttl index](https://docs.mongodb.org/manual/core/index-ttl/)._

db.items.createIndex( { "ttl": 1 }, { expireAfterSeconds: 30 } ), (*23)


### Mysqli Use it if you will you have mysqlnd available in your system. ``` php <?php use Desarrolla2\Cache\Cache; use Desarrolla2\Cache\Adapter\Mysqli; $adapter = new Mysqli(); $adapter->setOption('ttl', 3600); $cache = new Cache($adapter);

``` php <?php, (*24)

use Desarrolla2\Cache\Cache; use Desarrolla2\Cache\Adapter\Mysqli;
use \mysqli as Backend, (*25)

$backend = new Backend(); // configure it here, (*26)

$cache = new Cache(new Mysqli($backend));, (*27)


### NotCache Use it if you will not implement any cache adapter is an adapter that will serve to fool the test environments. ### Predis Use it if you will you have redis available in your system. You need to add predis as dependency in your composer file. ``` json "require": { //... "predis/predis": "~1.0.0" }

other version will have compatibility issues., (*28)

``` php <?php, (*29)

use Desarrolla2\Cache\Cache; use Desarrolla2\Cache\Adapter\Predis;, (*30)

$adapter = new Predis(); $cache = new Cache($adapter);, (*31)


If you need to configure your predis client, you will instantiate it and pass it to constructor. ``` php <?php use Desarrolla2\Cache\Cache; use Desarrolla2\Cache\Adapter\Predis; use Predis\Client as Backend $adapter = new Predis(new Backend($options)); $cache = new Cache($adapter);

Coming soon

This library implements other adapters as soon as possible, feel free to send new adapters if you think it appropriate., (*32)

This can be a list of pending tasks., (*33)

  • Cleaning cache
  • MemcachedAdapter
  • Other Adapters

Contact

You can contact with me on @desarrolla2., (*34)

The Versions

02/02 2016

dev-master

9999999-dev https://github.com/desarrolla2/Cache/

Provides an cache interface for several adapters Apc, Apcu, File, Mongo, Memcache, Memcached, Mysql, Mongo, Redis is supported. New adapters is comming!

  Sources   Download

MIT

The Development Requires

file cache redis memcache apc memcached mysql mongo apcu

02/02 2016

5.3.x-dev

5.3.9999999.9999999-dev https://github.com/desarrolla2/Cache/blob/master/README.md

Provides an cache interface for several adapters (Apc, File, Mongo, Memcached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file cache redis apc memcached mysql mongo

02/02 2016

dev-stable

dev-stable https://github.com/desarrolla2/Cache/blob/master/README.md

Provides an cache interface for several adapters (Apc, File, Mongo, Memcached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file cache redis apc memcached mysql mongo

02/02 2016

5.3

5.3.0.0 https://github.com/desarrolla2/Cache/blob/master/README.md

Provides an cache interface for several adapters (Apc, File, Mongo, Memcached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file cache redis apc memcached mysql mongo

27/10 2015

v2.0.0

2.0.0.0 https://github.com/desarrolla2/Cache/

Provides an cache interface for several adapters Apc, Apcu, File, Mongo, Memcache, Memcached, Mysql, Mongo, Redis is supported. New adapters is comming!

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

file cache redis memcache apc memcached mysql mongo apcu

27/10 2015

dev-coveralls

dev-coveralls https://github.com/desarrolla2/Cache/

Provides an cache interface for several adapters Apc, Apcu, File, Mongo, Memcache, Memcached, Mysql, Mongo, Redis is supported. New adapters is comming!

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

file cache redis memcache apc memcached mysql mongo apcu

27/10 2015

dev-scrutinizer

dev-scrutinizer https://github.com/desarrolla2/Cache/

Provides an cache interface for several adapters Apc, Apcu, File, Mongo, Memcache, Memcached, Mysql, Mongo, Redis is supported. New adapters is comming!

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

file cache redis memcache apc memcached mysql mongo apcu

22/10 2015

1.8.x-dev

1.8.9999999.9999999-dev https://github.com/desarrolla2/Cache/

Provides an cache interface for several adapters Apc, Apcu, File, Mongo, Memcache, Memcached, Mysql, Mongo, Redis is supported. New adapters is comming!

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

file cache redis memcache apc memcached mysql mongo apcu

22/10 2015

1.8.1

1.8.1.0 https://github.com/desarrolla2/Cache/

Provides an cache interface for several adapters Apc, Apcu, File, Mongo, Memcache, Memcached, Mysql, Mongo, Redis is supported. New adapters is comming!

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

file cache redis memcache apc memcached mysql mongo apcu

06/11 2014

v1.8.0

1.8.0.0 https://github.com/desarrolla2/Cache/blob/master/README.md

Provides an cache interface for several adapters (Apc, File, Mongo, Memcached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file cache redis apc memcached mysql mongo

06/11 2014

v1.7.1

1.7.1.0 https://github.com/desarrolla2/Cache/blob/master/README.md

Provides an cache interface for several adapters (Apc, File, Mongo, Memcached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file cache redis apc memcached mysql mongo

07/10 2013

v1.7.0

1.7.0.0 https://github.com/desarrolla2/Cache/blob/master/README.md

Provides an cache interface for several adapters (Apc, File, Mongo, Memcached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file cache redis apc memcached mysql mongo

10/07 2013

v1.6.0

1.6.0.0 https://github.com/desarrolla2/Cache/blob/master/README.md

Provides an cache interface for several adapters (Apc, File, Mongo, Memcached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file cache redis apc memcached mysql mongo

30/06 2013

v1.5.0

1.5.0.0 https://github.com/desarrolla2/Cache/blob/master/README.md

Provides an cache interface for several adapters (Apc, File, Mongo, Memcached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file cache redis apc memcached mysql mongo

30/06 2013

v1.4.0

1.4.0.0 https://github.com/desarrolla2/Cache/blob/master/README.md

Provides an cache interface for several adapters (Apc, File, Mongo, Memcached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file cache redis apc memcached mysql mongo

26/04 2013

v1.3.1

1.3.1.0 https://github.com/desarrolla2/Cache/blob/master/README.md

Provides an cache interface for several adapters (Apc, File, Mongo, Memcached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file cache redis apc memcached mysql mongo

25/04 2013

v1.3.0

1.3.0.0 https://github.com/desarrolla2/Cache/blob/master/README.md

Provides an cache interface for several adapters (Apc, File, Mongo, Memcached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file cache redis apc memcached mysql mongo

24/04 2013

v1.2.0

1.2.0.0 https://github.com/desarrolla2/Cache/blob/master/README.md

Provides an cache interface for several adapters (Apc, File, Mongo, Memcached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

file cache redis apc memcached mysql mongo

25/11 2012

v1.1.0

1.1.0.0 https://github.com/desarrolla2/Cache/blob/master/README.md

Provides an cache interface for several adapters (Apc, File, Mongo, Memcached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

file cache redis apc memcached mysql mongo

24/10 2012

v1.0.0

1.0.0.0 https://github.com/desarrolla2/Cache

Provides an cache interface for several adapters (Apc, File, Mencached, Mysql, ... )

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

cache apc memcached mysql cache file cache