Code Monkey home page Code Monkey logo

php-cache's Introduction

chillerlan/php-cache

A psr/simple-cache implementation for PHP 8.1+.

PHP Version Support version license Coverage Codacy Packagist downloads
Continuous Integration

Features:

Requirements

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:

(note: replace dev-main with a version constraint, e.g. ^4.1 - see releases for valid versions)

{
	"require": {
		"php": "^8.1",
		"chillerlan/php-cache": "dev-main"
	}
}

Installation via terminal: composer require chillerlan/php-cache

Profit!

Usage

Just invoke a cache instance with the desired CacheInterface like so:

// Redis
$redis = new Redis;
$redis->pconnect('127.0.0.1', 6379);

$cache = new RedisCache($redis);

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

$cache = new MemcachedCache($memcached);

// APCU
$cache = new APCUCache;

// File
$cache = new FileCache(new CacheOptions(['cacheFilestorage' => __DIR__.'/../.cache']));

// Session
$cache = new SessionCache(new CacheOptions(['cacheSessionkey' => '_my_session_cache']));

// Memory
$cache = new MemoryCache;

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! ๐Ÿ™ˆ

php-cache's People

Contributors

bahramsadin avatar codemasher avatar lucidlemon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

php-cache's Issues

Slight mistype in your README file

Hi there,

Thanks for this cache library, I used it in a prototype testing various cache methods - worked a treat!

One thing that tripped me up however was the following README example;

// File
$cache = new FileCache(new CacheOptions(['filestorage' => __DIR__.'/../.cache']));

Should be;

// File
$cache = new FileCache(new CacheOptions(['cacheFilestorage' => __DIR__.'/../.cache']));

i.e. filestorage should be cacheFilestorage

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.