PHPackages                             maplephp/cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. maplephp/cache

ActiveLibrary[Caching](/categories/caching)

maplephp/cache
==============

MaplePHP Cache, user-friendly caching library with full PSR-6 and PSR-16 support.

v2.0.0(4mo ago)21563Apache-2.0PHPPHP &gt;=8.2

Since Nov 27Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/MaplePHP/Cache)[ Packagist](https://packagist.org/packages/maplephp/cache)[ Docs](https://wazabii.se)[ RSS](/packages/maplephp-cache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (3)

MaplePHP - Cache
================

[](#maplephp---cache)

MaplePHP Cache, a clean and user-friendly caching library. MaplePHP Cache is designed to provide a seamless caching experience with simplicity and ease of use as its core principles. Whether you're familiar with **PSR-6** or **PSR-16**, this library offers a smooth and intuitive caching solution for your PHP applications.

Installation
------------

[](#installation)

```
composer require maplephp/cache

```

Initiate the cache engine
-------------------------

[](#initiate-the-cache-engine)

Start with initiate the MaplePHP Cache class and pass on a Handler to it.

```
use MaplePHP\Cache\Cache;
use MaplePHP\Cache\Handlers\FileSystemHandler;

$cache = new Cache(new FileSystemHandler(dirname(__FILE__)."/storage/cache"));

```

Usage
-----

[](#usage)

It is super easy to use

```
$expireInOneHour = 3600; // 3600 seconds = 1 hour
if(!$cache->has("test") && $cache->set("test", "Lorem ipsum dolor", $expireInOneHour)) {
	echo "Cache has been set";
}
echo "Get cache: ".$cache->get("test");

```

### Error handling

[](#error-handling)

While not required, it is advisable to handle critical throwable errors that may occur, such as an invalid cache key, insufficient file permissions, or possible connection issues with a cache server. Logging these exceptions can be beneficial for error tracking and troubleshooting purposes.

```
$cache = new Cache(new FileSystemHandler(dirname(__FILE__)));
try {
	// Invalid key set
	print_r($cache->get("te st"));
} catch (Exception $e) {
	// Will trigger: Invalid cache key. Only alphanumeric characters, underscores, and dots are allowed.
	echo $e->getMessage();
}

```

Handlers
--------

[](#handlers)

### File system

[](#file-system)

Save cache as a file on you system.

**Arg1:** (string) Path to directory where you want to save the cache fiels

```
use MaplePHP\Cache\Handlers\FileSystemHandler;
$fileSystem = new FileSystemHandler(dirname(__FILE__)."/storage/cache");

```

### Memcached

[](#memcached)

Use Memcached to save cache in memory **(high performance)**

**Arg1:** (string|array) Host to server (or get default with class constant "MemcachedHandler::HOST")

**Arg2:** (int|null) Port to server (or get default with class constant "MemcachedHandler::PORT")

**Arg3:** (int) Weight to server (Arg is default 0 but you can also set it with default with class constant "MemcachedHandler::WEIGHT")

```
use MaplePHP\Cache\Handlers\MemcachedHandler;
// One server
$memcached = new MemcachedHandler(MemcachedHandler::HOST, MemcachedHandler::PORT, MemcachedHandler::WEIGHT);
// Multiple servers
$memcached = new MemcachedHandler([
	["Memcached.server1.com", 11211, 1], // Weight "1" (this server has priority)
	["Memcached.server2.com", 11212, 2],
	["Memcached.server3.com", 11300, 3]
]);

```

Command list (PSR-16)
---------------------

[](#command-list-psr-16)

#### Get a cache item

[](#get-a-cache-item)

Can return mixed values if successful if miss then return default value. The default value is **not** required and is by default **null**.

```
$cache->get("test", "Default value");

```

#### Check if cache item exists

[](#check-if-cache-item-exists)

Will return bool

```
$cache->has("test");

```

#### Set a cache item

[](#set-a-cache-item)

It is allowed to set cache values of mixed types like strings, arrays and including PSR-7: HTTP Streams. Will return bool.

```
// Set cache with 1 hour lifetime
$cache->set("test", "Lorem ipsum dolor", 3600);
// Set cache that will persist
$cache->set("test2", "Lorem ipsum dolor");

```

#### Delete a cache item

[](#delete-a-cache-item)

Will return bool

```
$cache->delete("test");

```

#### Clear and auto delete all cache items

[](#clear-and-auto-delete-all-cache-items)

Will return bool

```
$cache->clear();

```

#### Get multiple cache items

[](#get-multiple-cache-items)

Will return array with mixed values if successful, if miss then return default value. The default value is **not** required and is by default **null**.

```
$cache->getMultiple(["test1", "test2"], "Default value");

```

#### Set multiple cache items

[](#set-multiple-cache-items)

Will return bool

```
$cache->setMultiple(["test1" => "Lorem", "test2" => "Ipsum"], 3600);

```

#### Delete multiple cache items

[](#delete-multiple-cache-items)

Will return bool

```
$cache->deleteMultiple(["test1", "test2"]);

```

PSR-6 Example
-------------

[](#psr-6-example)

If your application needs advanced caching features, hierarchical caching, or cache tagging, PSR-6 is a more suitable choice.

```

use MaplePHP\Cache\Handlers\FileSystemHandler;
$cache = new FileSystemHandler(dirname(__FILE__)."/storage/cache");

$item = $cache->getItem('test');

try {
	if(!$item->isHit()) {
		$item->set(["Lorem 1", "Lorem 2"])->expiresAfter(3600);
		$cache->save($item);

		echo "Insert to cache: ";
		print_r($item->get());

	} else {
		echo "Read from cache: ";
		print_r($item->get());
	}

} catch (Exception $e) {
	echo $e->getMessage();
}

```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance77

Regular maintenance activity

Popularity17

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~776 days

Total

2

Last Release

126d ago

Major Versions

v1.0.0 → v2.0.02026-01-12

PHP version history (2 changes)v1.0.0PHP &gt;=8.0

v2.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/724b188e785081275926c5b9c07082e2b3f4afb797efdda61eb1630457e17824?d=identicon)[wazabii](/maintainers/wazabii)

---

Top Contributors

[![wazabii8](https://avatars.githubusercontent.com/u/6400238?v=4)](https://github.com/wazabii8 "wazabii8 (7 commits)")[![danielRConsid](https://avatars.githubusercontent.com/u/169045496?v=4)](https://github.com/danielRConsid "danielRConsid (1 commits)")

---

Tags

cachecache-enginefilesystemmemcachememcachedphppsr-16psr-6psr-6-psr-16simple-cachestoragefilesystemcachingpsr-16psr-6memcached

### Embed Badge

![Health badge](/badges/maplephp-cache/health.svg)

```
[![Health](https://phpackages.com/badges/maplephp-cache/health.svg)](https://phpackages.com/packages/maplephp-cache)
```

###  Alternatives

[matthiasmullie/scrapbook

Scrapbook is a PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APCu, SQL and additional capabilities (e.g. transactions, stampede protection) built on top.

3212.5M32](/packages/matthiasmullie-scrapbook)[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[laminas/laminas-cache

Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output

1076.9M130](/packages/laminas-laminas-cache)[cache/filesystem-adapter

A PSR-6 cache implementation using filesystem. This implementation supports tags

705.8M82](/packages/cache-filesystem-adapter)[apix/cache

A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache taggging and indexing to Redis, Memcached, PDO/SQL, APC and other adapters.

114542.8k6](/packages/apix-cache)[cache/simple-cache-bridge

A PSR-6 bridge to PSR-16. This will make any PSR-6 cache compatible with SimpleCache.

423.1M27](/packages/cache-simple-cache-bridge)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
