flatphp/cache

cache component

v3.0.0 2022-02-02 07:16 UTC

This package is auto-updated.

Last update: 2024-11-29 04:39:58 UTC


README

Light cache component;

relate: https://github.com/flatphp/memstore

Install

composer require "flatphp/cache"

Init Config

use Flatphp\Memstore\Conn;
use Flatphp\Cache\Cache;

Conn::init(array(
    'memcache' => ['host' => '127.0.0.1', 'port' => 11211]
));

Cache::init(array(
    'expiration' => 3600, // the default expiration, 0 forever[default]
    'storage' => 'memcache',
));

// -------- OR --------------------

Cache::init(array(
    'expiration' => 3600, // the default expiration, 0 forever[default]
    'storage' => array(
        'driver' => 'redis',
	'host' => 'localhost',
	'port' => 6379
    )
));

Useage

use Flatphp\Cache\Cache;

Cache::set('test', 1, 60);
echo Cache::get('test');
Cache::delete('test');
Cache::flush();

Cache::increment('test', 2);
Cache::decrement('test', 2);

Cache::getData('test', function(){
    return 'hello';
});