2017 © Pedro Peláez
 

library gw-cache

PHP simple cache classes

image

gwa/gw-cache

PHP simple cache classes

  • Thursday, May 14, 2015
  • by gwa
  • Repository
  • 3 Watchers
  • 0 Stars
  • 679 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

gwCache

A simple but flexible PHP cache, (*1)

Quality Score Build Status, (*2)

Usage

Installation

Install package via composer., (*3)

composer require gwa/gw-cache

Using the cache

use Gwa\Cache\Cache;

// Create a persistence layer for the cache
// Cache directory should be writable.
// (Cache will try to create it if it does not exist.)
$cachedir = __DIR__ . '/cachestore';
$persistence = new CacheDirectoryPersistence($cachedir);



// Set an optional group for the cache
$group = '';

// Set cache validity in minutes
$cacheminutes = 60 * 12;

// create a cache instance using an identifier unique to the group
$cache = new Cache('myidentifier', $group, $cacheminutes);
$cache->setPersistence($persistence);



$iscached = $cache->isCached(); // false

// write a value to the cache
$cache->set('foo');

// new object, same group and identifier
$cache2 = new Cache('myidentifier', $group, $cacheminutes);
$cache2->setPersistence($persistence);
$iscached = $cache2->isCached(); // true
$value = $cache2->get(); // 'foo'

// clear the cache
$cache2->clear();
$iscached = $cache2->isCached(); // false

Using a factory

Instead of always passing in the persistence layer, a factory can be used., (*4)

The factory could be set up as a service in your app (using, for example, Pimple). Creating a cache instance is then not dependent on the persistence layer., (*5)

$factory = new CacheFactory(new CacheDirectoryPersistence($cachedir));

$cache = $factory->create('myidentifier', $group, $cacheminutes);

Caching serialized data

To cache complex PHP types (ie. objects), set the cache type argument when creating the cache instance., (*6)

$cache = new Cache('myidentifier', $group, $cacheminutes, Cache::TYPE_OBJECT);

// with a factory
$cache = $factory->create('myidentifier', $group, $cacheminutes, Cache::TYPE_OBJECT);

Custom persistence layers

You can roll your own persistence layer (MySQL, memcache, redis) by creating a class that implements the CachePersistenceInterface interface., (*7)

If you are using a factory-as-a-service architecture, you can use different persistence layers in different environments without changing the code that uses the service., (*8)

Contributing

All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code., (*9)

Fork the project, create a feature branch, and send us a pull request., (*10)

To ensure a consistent code base, you should make sure the code follows the Coding Standards which we borrowed from PSR-2., (*11)

The easiest way to do make sure you're following the coding standard is to run vendor/bin/php-cs-fixer fix before committing., (*12)

The Versions

14/05 2015

dev-master

9999999-dev https://github.com/gwa/gwCache

PHP simple cache classes

  Sources   Download

MIT

The Requires

 

The Development Requires

14/05 2015
14/05 2015

dev-develop

dev-develop https://github.com/gwa/gwCache

PHP simple cache classes

  Sources   Download

MIT

The Requires

 

The Development Requires

08/05 2015
08/05 2015

v1.4.1

1.4.1.0 https://github.com/gwa/gwCache

PHP simple cache classes

  Sources   Download

MIT

The Requires

 

The Development Requires

30/04 2015
10/02 2015
23/10 2014

v1.2

1.2.0.0 https://github.com/gwa/gwCache

PHP simple cache classes

  Sources   Download

MIT

The Requires

 

03/09 2014

v1.1

1.1.0.0 https://github.com/gwa/gwCache

PHP simple cache classes

  Sources   Download

MIT

The Requires

 

03/09 2014

v1.0

1.0.0.0 https://github.com/gwa/gwCache

PHP simple cache classes

  Sources   Download

MIT

The Requires