PHP cache implementation supporting memcached

Overview

php cache implementation (PSR-6 and PSR-16)

License PHP 8.0 Latest Stable Version Total Downloads CI

Support for memcached and APCu is included.

Memcached

$memcached = new Memcached();
$memcached->addServer("127.0.0.1", 11211, 50]);
$pool = new Cache\Pool\Memcached($memcached);

$cache = new Cache\Cache($pool);

APCu

$pool = new Cache\Pool\APCu();
$cache = new Cache\Cache($pool);

Blackhole

The blackhole pool is a dummy pool, which does not do any caching. It can be used on a development environment, when caching should be disabled.

$pool = new Cache\Pool\Blackhole();
$cache = new Cache\Cache($pool);

Memory

A cache pool which uses an instance variable of the pool object as cache.

$pool = new Cache\Pool\Memory();
$cache = new Cache\Cache($pool);

Additional methods

Besides, the PSR standards, the Cache has implemented some useful extra methods.

getSet

getSet invokes a closure, if the key was not found inside the cache. This helps to build a linear code base, without additional conditions checking whether the key was found or not.

If the key was found, the value is returned directly, without invkoing the closure.

$pool = new Cache\Pool\APCu();
$cache = new Cache\Cache($pool);

$val = $cache->getSet('mykey', function() {
    // ... do some expensive calculations
    return $val;
});

Grouping

If you want to invalidate a group of cache items, by only removing one key, this could be done by using the group feature.

$groupkey = 'mygroup';

$cache->setGrouped($groupkey, 'key1', $val1);
$cache->setGrouped($groupkey, 'key2', $val2);
$cache->setGrouped($groupkey, 'key-' . uniqid(), $val2);

$cache->delete($groupkey); // invalidates key1, key2, key-xxxx

$val = $cache->getGrouped($groupkey, 'key1'); // $val is null

getSetGrouped works in the same way as getSet, but with the additional group key.

You might also like...
A fast, lock-free, shared memory user data cache for PHP

Yac is a shared and lockless memory user data cache for PHP.

PHP Cache Duration
PHP Cache Duration

PHP Cache Duration Introduction A readable and fluent way to generate PHP cache time. Built and written by Ajimoti Ibukun Quick Samples Instead of thi

Simple artisan command to debug your redis cache. Requires PHP 8.1 & Laravel 9
Simple artisan command to debug your redis cache. Requires PHP 8.1 & Laravel 9

🔎 php artisan cache:debug Simple artisan command to debug your redis cache 🚀 Installation You can install the package via composer: composer require

The place to keep your cache.

Stash - A PHP Caching Library Stash makes it easy to speed up your code by caching the results of expensive functions or code. Certain actions, like d

Cache slam defense using a semaphore to prevent dogpile effect.

metaphore PHP cache slam defense using a semaphore to prevent dogpile effect (aka clobbering updates, stampending herd or Slashdot effect). Problem: t

Doctrine Cache component

Doctrine Cache Cache component extracted from the Doctrine Common project. Documentation This library is deprecated and will no longer receive bug fix

Simple cache abstraction layer implementing PSR-16

sabre/cache This repository is a simple abstraction layer for key-value caches. It implements PSR-16. If you need a super-simple way to support PSR-16

More Than Just a Cache: Redis Data Structures
More Than Just a Cache: Redis Data Structures

More Than Just a Cache: Redis Data Structures Redis is a popular key-value store, commonly used as a cache or message broker service. However, it can

Releases(3.1.0)
Owner
Michael Bretterklieber
Michael Bretterklieber
A fast, light-weight proxy for memcached and redis

twemproxy (nutcracker) twemproxy (pronounced "two-em-proxy"), aka nutcracker is a fast and lightweight proxy for memcached and redis protocol. It was

Twitter 11.6k Dec 1, 2022
Graphic stand-alone administration for memcached to monitor and debug purpose

PHPMemcachedAdmin Graphic stand-alone administration for memcached to monitor and debug purpose This program allows to see in real-time (top-like) or

Cyrille Mahieux 249 Nov 15, 2022
A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache tagging and indexing.

Apix Cache, cache-tagging for PHP Apix Cache is a generic and thin cache wrapper with a PSR-6 interface to various caching backends and emphasising ca

Apix 111 Nov 26, 2022
LRU Cache implementation in PHP

PHP LRU Cache implementation Intro WTF is a LRU Cache? LRU stands for Least Recently Used. It's a type of cache that usually has a fixed capacity and

Rogério Vicente 61 Jun 23, 2022
Distributed PSR-16 cache implementation for PHP 6 that uses browser cookies to store data

cookiecache Cache beyond the edge with cookies! This library provides a distributed PSR-16 compatible cache implementation for PHP 6 that uses browser

Colin O'Dell 8 Apr 19, 2022
PSR-6 cache implementation adapting a given PSR-16 instance

PSR-6 cache implementation adapting PSR-16 This package provides a PSR-6 cache instance when you only have a PSR-16 cache at hand. As PSR-6 is more fe

null 1 Oct 15, 2021
The cache component provides a Promise-based CacheInterface and an in-memory ArrayCache implementation of that

Cache Async, Promise-based cache interface for ReactPHP. The cache component provides a Promise-based CacheInterface and an in-memory ArrayCache imple

ReactPHP 329 Nov 21, 2022
:zap: Simple Cache Abstraction Layer for PHP

⚡ Simple Cache Class This is a simple Cache Abstraction Layer for PHP >= 7.0 that provides a simple interaction with your cache-server. You can define

Lars Moelleken 26 Jun 9, 2022
Elephant - a highly performant PHP Cache Driver for Kirby 3

?? Kirby3 PHP Cache-Driver Elephant - a highly performant PHP Cache Driver for Kirby 3 Commerical Usage Support open source! This plugin is free but i

Bruno Meilick 11 Apr 6, 2022
PHP local cache

__ ____ _________ ______/ /_ ___ / __ \/ ___/ __ `/ ___/ __ \/ _ \ / /_/ / /__/ /_/ / /__/ / / / __/ / ._

Jayden Lie 48 Sep 9, 2022