2017 © Pedro Peláez
 

library lib-cache

Cache library of the Ride framework.

image

ride/lib-cache

Cache library of the Ride framework.

  • Friday, May 18, 2018
  • by ride-user
  • Repository
  • 7 Watchers
  • 0 Stars
  • 3,220 Installations
  • 5 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 2 % Grown

The README.md

Ride: Cache Library

Cache library of the PHP Ride framework., (*1)

What's In This Library

CacheItem

A CacheItem is the container of your cached value. The implementation contains the logic to see if the cached item is valid and not stale., (*2)

An extension to tag your cache items is available through the TaggableCacheItem interface., (*3)

The GenericCacheItem class implements both interfaces., (*4)

CachePool

A CachePool is the backend or storage of your cache items. The implementation decides how to store your cache items. Each implementation has it's advantages and disadvantages. Your choice should depend on the context of cache usage and server environment., (*5)

Available implementations (all implement taggable cache items):, (*6)

  • ride\library\cache\pool\ApcCachePool: APC implementation
  • ride\library\cache\pool\DirectoryCachePool: Cache directory with one file per cached item
  • ride\library\cache\pool\FileCachePool: One file for the complete pool
  • ride\library\cache\pool\MemcacheCachePool: Memcache implementation
  • ride\library\cache\pool\XCacheCachePool: XCache implementation

CacheControl

A CacheControl provides an interface to expose the management of your caches to the UI., (*7)

Code Sample

Check the following code sample to see how the cache should be used:, (*8)

<?php

use ride\library\cache\pool\DirectoryCachePool;
use ride\library\system\System;

function foo(System $system) {
    // cache initialization
    $cacheDirectory = $system->getFileSystem()->getFile('/path/to/cache');
    $cachePool = new DirectoryCachePool($cacheDirectory);

    // cache usage
    $cacheItem = $cachePool->get('item.cache.key');
    if (!$cacheItem->isValid()) {
        // some value generation logic
        // ...

        // store value to the cache
        $cacheItem->setValue($value); // required
        $cacheItem->setTtl(60); // in seconds, optional
        $cacheItem->setTag('section'); // you can tag an item, optional

        $cachePool->set($cacheItem);
    } else {
        // retrieve value from cache
        $value = $cacheItem->getValue();
    }

    // cache flush
    $cachePool->flush(); // flush complete cache
    $cachePool->flush('item.cache.key'); // remove an item
    $cachePool->flushByTag('section'); // remove all items tagged with section
}

This code uses the item as returned from the pool to set the cached value., (*9)

When you warm up your cache in another place, you can easily create your cache item through the pool:, (*10)

<?php

use ride\library\cache\pool\CachePool;

function bar(CachePool $cachePool) {
    $cacheItem = $cachePool->create('item.cache.key');
    $cacheItem->setValue('some cache value');

    $cachePool->set($cacheItem);
}

Installation

You can use Composer to install this library., (*11)

composer require ride/lib-cache

The Versions

18/05 2018

dev-master

9999999-dev

Cache library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

18/05 2018

dev-develop

dev-develop

Cache library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

18/05 2018

1.1.0

1.1.0.0

Cache library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

29/03 2018

1.0.2

1.0.2.0

Cache library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

08/09 2016

1.0.1

1.0.1.0

Cache library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

28/06 2016

1.0.0

1.0.0.0

Cache library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

25/09 2015

0.3.0

0.3.0.0

Cache library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

24/06 2015

0.2.0

0.2.0.0

Cache library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

23/04 2015

0.1.2

0.1.2.0

Cache library of the Ride framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

14/10 2013

0.1.1

0.1.1.0

Cache library of the Pallo framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

14/10 2013

0.1.0

0.1.0.0

Cache library of the Pallo framework.

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd