anekdotes/cache

Allows caching using different drivers

2.0.0 2021-11-24 16:10 UTC

This package is auto-updated.

Last update: 2024-04-24 21:06:42 UTC


README

Latest Stable Version Build Status codecov.io StyleCI License Total Downloads Codacy Badge

Allows caching using different drivers

Installation

Install via composer into your project:

composer require anekdotes/cache

Usage

Declare your Cache object depending on your Driver. After construction, all Cache objects can be manipulated the same way.

use Anekdotes\Cache\FileCache;
$path = 'tmp/cache/'; //The slash at the end is IMPORTANT. MAKE SURE YOU HAVE IT!
$cache = new FileCache($path);
$key = 'Toaster';
$value = 'Test';
$minutes = 5;
$cache->set($key, $value, $minutes);
$cache->get('Toaster'); //Returns 'Test' as long as this call is made in a 5 minute time-frame past the previous set call.
$cache->time('Toaster'); //Return the datetime object of when this key has been set
$cache->forget('Toaster');
$cache->has('Toaster'); //Returns false.

Notes

  • The ArrayCache driver does not currently analyze expiration time. This means all array cached objects last forever.

  • The FileCache driver does not implement the increment and decrement functions. Both functions throw LogicException under this driver.

  • Setting a cache's expiration to zero will make it never expire. Using ```$cache->forever()````does the same thing.

  • You can use $cache->flush() to remove all data in the cache.