calgamo/cache

This package is abandoned and no longer maintained. The author suggests using the calgamolib/cache package instead.

Cache library for Calgamo Framework.

0.6.1 2019-11-07 19:21 UTC

This package is auto-updated.

Last update: 2019-11-19 18:24:02 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Code Climate Total Downloads

Description

Calgamo/Cache is a cache library for calgamo framework.

Feature

  • PSR16: SimpleCache compliant
  • File cache
  • Array cache

Demo(FileCache)

config

$config = [
    'cache' => [
        'root' => '/path/to/cache',
        'expire' => 5,      // expires 5 seconds after cache item is set
    ]
];

get/set

$cache = new FileCache($config);

$cache->set('my favorite artist', 'stevie wonder');

echo $cache->get('my favorite artist');    // stevie wonder

$cache->set('my favorite artist', 'justin bieber');

echo $cache->get('my favorite artist');    // justin bieber

expire

$cache = new FileCache($config);

$cache->set('my favorite artist', 'stevie wonder');

echo $cache->get('my favorite artist');    // stevie wonder

sleep(6);

echo $cache->get('my favorite artist');    // 

$cache->set('my favorite artist', 'stevie wonder', 10);

sleep(6);

echo $cache->get('my favorite artist');    // stevie wonder

delete

$cache = new FileCache($config);

$cache->set('my favorite artist', 'stevie wonder');

echo $cache->get('my favorite artist');     // stevie wonder

$cache->delete('my favorite artist');

echo $cache->get('my favorite artist');     //

clear

$cache = new FileCache($config);

$cache->set('my favorite artist', 'stevie wonder');
$cache->set('my favorite movie', 'Jurassic Park');

echo $cache->get('my favorite artist');     // stevie wonder
echo $cache->get('my favorite movie');      // Jurassic Park

$cache->clear();

echo $cache->get('my favorite artist');     // 
echo $cache->get('my favorite movie');      // 

get multiple cache

$cache = new FileCache($config);

$cache->set('my favorite artist', 'stevie wonder');
$cache->set('my favorite movie', 'Jurassic Park');

$values = $cache->getMultiple([
    'my favorite artist', 'my favorite movie'
]);

echo print_r($values, true);
// Array
// (
//     [my favorite artist] => stevie wonder
//     [my favorite movie] => Jurassic Park
// )

set multiple cache

$cache = new FileCache($config);

$cache->setMultiple([
    'my favorite artist' => 'stevie wonder',
    'my favorite movie' => 'Jurassic Park',
]);

echo $cache->get('my favorite artist');     // stevie wonder
echo $cache->get('my favorite movie');      // Jurassic Park

array cache

$cache = new ArrayCache($config);

$cache->set('my favorite artist', 'stevie wonder');

echo $cache->get('my favorite artist');     // stevie wonder

sleep(6);

echo $cache->get('my favorite artist');     // 

Usage

1. Make config array

  • cache/root is required for FileCache
  • cahe/expire is optional(unit: seconds)

2. Create cache object

  • pass config array to the constructor

3. Set or get cache

  • use get() method to get cache item
  • use set() method to update cache item

Requirement

PHP 7.1 or later

Installing calgamo/cache

The recommended way to install calgamo/cache is through Composer.

composer require calgamo/cache

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

License

This library is licensed under the MIT license.

Author

stk2k

Disclaimer

This software is no warranty.

We are not responsible for any results caused by the use of this software.

Please use the responsibility of the your self.