2017 © Pedro Peláez
 

library cache

Yet another caching implementation

image

websoftwares/cache

Yet another caching implementation

  • Saturday, April 6, 2013
  • by Websoftwares
  • Repository
  • 0 Watchers
  • 1 Stars
  • 36 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Cache

Yet another caching implementation., (*1)

Build Status, (*2)

Usage

Basic usage applies to all cache storage options, (*3)

use Websoftwares\Cache, Websoftwares\Storage\File;

$cache = Cache::storage(new File());

$cache->save('key',["a","b","c"]);

// Retrieve the cache

$cache->get('key');

Storage

Available storage options:, (*4)

  • Apc (saves the cache to apc)
  • File (saves the cache to a file)
  • Memcache (save the cache to a memcache instance)
  • Memcached (save the cache to a memcached instance)
  • MongoDB (save the cache to a mongo instance)
  • Redis (save the cache to a redis instance)
  • Riak (save the cache to a riak instance)

Apc

use Websoftwares\Cache, Websoftwares\Storage\Apc;

$apc = Cache::storage(new Apc())
 ->setExpiration(86400);

$apc->save('key',["a","b","c"]);

// Retrieve the cache

$apc->get('key');

File

use Websoftwares\Cache, Websoftwares\Storage\File;

$cache = Cache::storage(new File())
 ->setPath('/super/spot')
 ->setExpiration(86400);

$cache->save('key',["a","b","c"]);

// Retrieve the cache

$cache->get('key');

Memcache

This requires u have the PHP memcache extension installed., (*5)

on Debian/Ubuntu systems for example install like this (requires administrative password)., (*6)

sudo apt-get install php5-memcache

use Websoftwares\Cache, Websoftwares\Storage\Memcache;

$memcache = Cache::storage(new Memcache())
    ->setConnection(function() {
        $instance = new \Memcache;
        $instance->connect('localhost','11211');
        return $instance;
    })
    ->setExpiration(86400);

$memcache->save('key',["a","b","c"]);

// Retrieve the cache

$memcache->get('key');

Memcached

This requires u have the PHP memcached extension installed., (*7)

on Debian/Ubuntu systems for example install like this (requires administrative password)., (*8)

sudo apt-get install php5-memcached

use Websoftwares\Cache, Websoftwares\Storage\Memcached;

$memcached = Cache::storage(new Memcached())
    ->setConnection(function() {
        $instance = new \Memcached();
        $instance->addServer("localhost", 11211);
        return $instance;
    })
    ->setExpiration(86400);

$memcached->save('key',["a","b","c"]);

// Retrieve the cache

$memcached->get('key');

Mongo

This storage option makes use of the "ensureIndex" method option "expireAfterSeconds"., (*9)

This option can only be used if the following requirements are met., (*10)

Requirements: * Latest PHP Mongo extension installed * mongoDB deamon version 2.2+ | read more, (*11)

On debian/ubuntu systems run the following command to install the mongo extension (requires administrator password)., (*12)

sudo pecl install mongo
use Websoftwares\Cache, Websoftwares\Storage\Mongo;

$mongo = Cache::storage(new Mongo())
    ->setConnection(function() {
        $m = new \MongoClient();
        $db = $m->mongocache;
        return $db;
    })
    ->setCollection('test')
    ->setExpiration(86400);

$mongo->save('key',["a","b","c"]);

// Retrieve the cache

$mongo->get('key');

Redis

This requires u have the PHP Predis package installed., (*13)

use Websoftwares\Cache, Websoftwares\Storage\Redis;

$redis = Cache::storage(new Redis())
    ->setConnection(function() {
        $client = new \Predis\Client([
            'scheme'   => 'tcp',
            'host'     => '127.0.0.1',
            'port'     => 6379,
        ]);
        return $client;
    })
    ->setExpiration(86400);

$redis->save('key',["a","b","c"]);

// Retrieve the cache

$redis->get('key');

Riak

This requires u have the PHP Riak official package installed., (*14)

use Websoftwares\Cache, Websoftwares\Storage\Riak;

$riak = Cache::storage(new Riak())
    ->setConnection(function() {
        $client = new \Basho\Riak\Riak('127.0.0.1', 8098);
        return $client;
    })
    ->setBucket('testBucket')
    ->setExpiration(86400);

$riak->save('key',["a","b","c"]);

// Retrieve the cache

$riak->get('key');

The Versions

06/04 2013

dev-master

9999999-dev

Yet another caching implementation

  Sources   Download

dbad

The Requires

  • php >=5.4.0

 

The Development Requires

by Boris Verhaaff

file cache redis memcache apc memcached mongo riak