2017 © Pedro Peláez
 

library kache

Simple cache system with support for multiple drivers.

image

laurent22/kache

Simple cache system with support for multiple drivers.

  • Sunday, February 16, 2014
  • by lau22
  • Repository
  • 1 Watchers
  • 2 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Kache

A simple cache system with support for multiple drivers and a focus on performance. There is only a minimal wrapper between the exposed API and the underlying driver so as to keep the library as fast as possible., (*1)

Installation

Either checkout the code and require src/Kache.php. Or use Composer:, (*2)

"require": { "laurent22/kache": "1.*" }

Setup

Using the file driver:

Kache::setup(array(
    'driver' => 'file',
    'path' => '/path/to/cache_folder',
));

Using the Redis driver:

Kache::setup(array(
    'driver' => 'redis',
    'server' => array(
        'host' => '127.0.0.1',
        'port' => 6379,
        'dbindex' => 1,
    ),
));

Using the null driver (to disable caching):

Kache::setup(array(
    'driver' => 'null',
));

Usage

The class instance can be accessed either via Konfig::instance() or by the convenience method k(). For example:, (*3)

k()->set('somekey', 'somevalue', 120); // Cache for 2 minutes
var_dump(k()->get('somekey'));
$k()->delete('somekey');

You may also use the getOrRun() method which will either return the given key or, if it doesn't exist, will do the following: - run the provided function. - set the key to the value returned by the function. This allows simplifying the boiler plate code needed when getting/setting cache values. For example, the following code:, (*4)

function getName() {
    $name = k()->get('name');
    if ($name !== null) return $name;
    $name = getNameFromDb();
    k()->set('name', $name, 600);
    return $name;
}

can be simplified to just this:, (*5)

function getName() {
    return k()->getOrRun('name', function() {
        return getNameFromDb();
    }, 600);
}

The Versions

16/02 2014

dev-master

9999999-dev

Simple cache system with support for multiple drivers.

  Sources   Download

MIT

by Laurent Cozic

16/02 2014

1.0

1.0.0.0

Simple cache system with support for multiple drivers.

  Sources   Download

MIT

by Laurent Cozic