Skip to content
This repository was archived by the owner on Nov 22, 2019. It is now read-only.

systemson/cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub last commit Latest Stable Version Latest Beta Version PHP from Packagist Build Status Coverage Status Total Downloads GitHub

Amber/Cache

Simple and fast cache system implementing PSR-16: interface for caching libraries

Getting started

Installation

With Composer

$ composer require amber/cache

API Usage

use Amber\Cache\Cache;

$cache = Cache::getInstance();

Drivers

Alternatively you can set the driver before geting the instance of the cache.

use Amber\Cache\Cache;

$cache = Cache::driver('file');

You can choose from these drivers:

$drivers = [
    'file'  => 'Amber\Cache\Driver\SimpleCache',
    'json'  => 'Amber\Cache\Driver\JsonCache',
    'array' => 'Amber\Cache\Driver\ArrayCache',
    'apcu'  => 'Amber\Cache\Driver\ApcuCache',
];

Or you could set the driver class:

$cache = Cache::driver(Amber\Cache\Driver\SimpleCache::class);

Finally you could instantiate the driver by yourself:

$cache = new \Amber\Cache\Driver\SimpleCache();

get()

Fetches a value from the cache.

$cache->get($key, $default = null);

set()

Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.

$cache->set($key, $value, $ttl = null);

delete()

Delete an item from the cache by its unique key.

$cache->delete($key);

clear()

Wipes clean the entire cache's keys.

$cache->clear();

has()

Determines whether an item is present in the cache.

$cache->has($key);

Multiple actions

getMultiple()

Obtains multiple cache items by their unique keys.

$cache->getMultiple($keys, $default = null);

setMultiple()

Persists a set of key => value pairs in the cache, with an optional TTL.

$cache->setMultiple($values, $ttl = null);

deleteMultiple()

Deletes multiple cache items in a single operation.

$cache->deleteMultiple($keys);

Static Usage

You can use all the method from the Cache class statically, like this:

use Amber\Cache\Cache;

Cache::set('key', 'value');

Cache::has('key'); // Returns true

Cache::get('key'); // Returns "value"

Cache::delete('key');

// Set the driver and then call the desired method.
Cache::driver('json')->set('key', 'value');

About

Simple cache system implementing PSR-16: interface for caching libraries

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages