Skip to content

chillerlan/php-cache

Repository files navigation

codemasher/php-cache

version license Travis Coverage Scrunitizer Code Climate

Features:

Requirements

  • PHP 7+
  • Memcached extension (optional)

Documentation

Installation using composer

You can simply clone the repo and run composer install in the root directory. In case you want to include it elsewhere, just add the following to your composer.json:

{
	"require": {
		"php": ">=7.0.3",
		"chillerlan/php-cache": "dev-master"
	}
}

Manual installation

Download the desired version of the package from master or release and extract the contents to your project folder. Point the namespace chillerlan\SimpleCache to the folder src of the package.

Profit!

Usage

Just invoke a Cache instance with the desired CacheDriverInterface like so:

// Memcached
$memcached = new Memcached('test');
$memcached->addServer('localhost', 11211);

$cacheDriver = new MemcachedDriver($memcached);

// File
$cacheDriver = new FileCacheDriver(__DIR__.'/../.cache');

// Session
$cacheDriver = new SessionCacheDriver('_session_cache');

// Memory
$cacheDriver = new MemoryCacheDriver;

// load the cache instance
$cache = new Cache($cacheDriver);

Methods

See: Psr\SimpleCache\CacheInterface

$cache->get(string $key, $default = null); // -> mixed
$cache->set(string $key, $value, int $ttl = null):bool
$cache->delete(string $key):bool
$cache->has(string $key):bool
$cache->clear():bool
$cache->getMultiple(array $keys, $default = null):array // -> mixed[]
$cache->setMultiple(array $values, int $ttl = null):bool
$cache->deleteMultiple(array $keys):bool

Disclaimer!

I don't take responsibility for molten memory modules, bloated hard disks, self-induced DoS, broken screens etc. Use at your own risk! 🙈

About

A psr/simple-cache (PSR-16) implementation

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages