PHPackages                             mrmanchot/simple-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. mrmanchot/simple-cache

ActiveLibrary

mrmanchot/simple-cache
======================

A simple and efficient PHP library for cache management.

1.2.8(1y ago)1391PHPPHP &gt;=7.0

Since Oct 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/MrManchot/SimpleCache)[ Packagist](https://packagist.org/packages/mrmanchot/simple-cache)[ RSS](/packages/mrmanchot-simple-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (20)Used By (0)

SimpleCache
===========

[](#simplecache)

SimpleCache is a lightweight and efficient PHP caching library, designed for ease of use and flexibility. Whether you're caching strings, arrays, objects, or booleans, SimpleCache provides a straightforward and intuitive API to speed up your PHP applications. With features like cache expiration, subdirectory organization, and security measures, it's an ideal solution for both small projects and large-scale applications.

Features
--------

[](#features)

- Easy to use
- Supports multiple data types: strings, arrays, objects, and booleans
- Allows setting cache expiration time
- Option to bypass cache
- Sanitizes cache keys for security
- Graceful error handling with warnings instead of exceptions

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

[](#installation)

Use Composer to install this library:

```
composer require mrmanchot/simple-cache
```

Usage
-----

[](#usage)

### Initialization

[](#initialization)

```
use Mrmanchot\SimpleCache\SimpleCache;
require 'vendor/autoload.php';

$cache = new SimpleCache('/path/to/cache/directory/');
```

### Basic Usage

[](#basic-usage)

```
// Set cache
$cache->set('key', 'value');

// Get cache
$value = $cache->get('key');
```

### Using Expiration Time

[](#using-expiration-time)

You can specify an expiration time in minutes using the `$delayMinutes` parameter.

```
// Set cache
$cache->set('key', 'value');

// Get cache, valid for 10 minutes
$value = $cache->get('key', 10);
```

### Storing Arrays, Objects, and Booleans

[](#storing-arrays-objects-and-booleans)

You can also store arrays, objects, and booleans.

```
// Storing an array
$cache->set('array_key', ['a' => 1, 'b' => 2]);

// Retrieving an array
$array = $cache->get('array_key');

// Storing an object
$object = new stdClass();
$object->property = 'value';
$cache->set('object_key', $object);

// Retrieving an object
$object = $cache->get('object_key');

// Storing a boolean
$cache->set('boolean_key', true);

// Retrieving a boolean
$boolean = $cache->get('boolean_key');
```

### Handling Cache Hits and Misses

[](#handling-cache-hits-and-misses)

When retrieving data from the cache, you can distinguish between a cache hit and a cache miss by checking if the returned value is null. If the value is null, it indicates that the data is not present in the cache (a cache miss), and you may need to compute or generate the value. If the value is not null, it is a cache hit, and you can use the cached value directly.

Here's an example of how to handle cache hits and misses:

```
$cachedValue = $cache->get('some_key');
if ($cachedValue === null) {
    // The value is not in the cache, compute/generate the value
}
```

### Using Subdirectories as Keys

[](#using-subdirectories-as-keys)

You can use subdirectories in keys for better organization. Note that keys are sanitized for security purposes, so only certain characters are allowed.

```
// Set cache in a subdirectory
$cache->set('user/1', 'value');

// Get cache from a subdirectory
$value = $cache->get('user/1');
```

### Clearing the Cache

[](#clearing-the-cache)

The `clear` method allows you to remove cached items based on a pattern. This is useful for batch invalidation of cache items.

```
// Clear a specific cache item
$cache->clear('key');

// Clear all cache items in a subdirectory
$cache->clear('user/*');

// Clear all cache items
$cache->clear('*');
```

### Run PHPUnit

[](#run-phpunit)

```
phpunit test/SimpleCacheTest.php

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.3% 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 ~19 days

Recently: every ~3 days

Total

19

Last Release

589d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/31999b3179ed3f97c652767c97b1706586dd798caa4d12acd49ce429542df707?d=identicon)[MrManchot](/maintainers/MrManchot)

---

Top Contributors

[![MrManchot](https://avatars.githubusercontent.com/u/2027380?v=4)](https://github.com/MrManchot "MrManchot (28 commits)")[![aomaxime](https://avatars.githubusercontent.com/u/148320838?v=4)](https://github.com/aomaxime "aomaxime (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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