2017 © Pedro Peláez
 

library cache

Cache interface

image

dc/cache

Cache interface

  • Thursday, December 8, 2016
  • by vegardlarsen
  • Repository
  • 2 Watchers
  • 0 Stars
  • 94 Installations
  • PHP
  • 8 Dependents
  • 4 Suggesters
  • 0 Forks
  • 1 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

DC\Cache - Caching interface, (*1)

Installation

$ composer install dc/cache

Or add it to composer.json:, (*2)

"require": {
    "dc/cache": "0.*",
}
$ composer install

This package suggests dc/cache-memcache, which is the only implementation at this point., (*3)

Getting started

This is just an interface. You probably should install dc/cache-memcahe or write your own implementation to the interface., (*4)

When you have, you can use the interface like this:, (*5)

$cache = new \SomeImplementation();
$cache->set('foo', 'bar');
echo $cache->get('foo'); // prints bar

A common pattern is that you want a specific value from the cache, and if it is a cache miss, you want to produce it:, (*6)

echo $cache->getWithFallback('foo', function() {
  return 'bar';
}); // prints bar
$cache->get('foo'); // now also prints bar

This syntax works with any callable, not just closures., (*7)

You can also use the return value to determine the validity., (*8)

$foo = $cache->getWithFallback("foo", 
    function($x) { return ["foo" => $x, "expires" => \DateInterval($x)]; }, 
    function($result) { return $result["expires"]; });

The Versions

08/12 2016

dev-master

9999999-dev http://github.com/digitalcreations/cache

Cache interface

  Sources   Download

MIT

The Development Requires

cache memcached

27/10 2014
04/05 2014