PHPackages                             lufiipe/simplecache - 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. lufiipe/simplecache

ActiveLibrary[Caching](/categories/caching)

lufiipe/simplecache
===================

Simple file system cache library for PHP

1.0.0(10mo ago)114MITPHPPHP ^7.4|^8.0CI passing

Since Jun 26Pushed 10mo agoCompare

[ Source](https://github.com/lufiipe/simplecache)[ Packagist](https://packagist.org/packages/lufiipe/simplecache)[ RSS](/packages/lufiipe-simplecache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

[![GitHub Release](https://camo.githubusercontent.com/0f33a7dc137eddc4f0ff81736a054951d1cd1b9c9c81b0e035fe147d5f57746a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6c7566696970652f73696d706c656361636865)](https://github.com/lufiipe/simplecache/releases)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/c826d30203f1f0462cbcfb3bb90d1a479fcaee4dd3f9b228a92d85fa8471984a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c7566696970652f73696d706c6563616368652f7068705f72756e5f74657374732e796d6c)](https://github.com/lufiipe/simplecache/actions)[![GitHub License](https://camo.githubusercontent.com/f288d930c998d39e33131091152d158dae74cf17eb36c8bfa9b8b19fdc4598f1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c7566696970652f73696d706c6563616368653f636f6c6f723d79656c6c6f77)](LICENSE)

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

[](#simplecache)

Simple cache library for PHP based on PSR-16. It uses a hybrid system: fast in-memory storage for temporary data and file storage for persistent data.

Install
-------

[](#install)

```
composer require lufiipe/simplecache

```

Usage
-----

[](#usage)

```
use LuFiipe\SimpleCache\Cache;

$cache = new Cache();
$cache->set('key', 'value');
$value = $cache->get('key');
```

Setup the cache
---------------

[](#setup-the-cache)

The `Cache` class accepts the following arguments:

- string `$cacheDir` : Path to a writable folder for storing cache files. If not provided, default system 'tmp' folder will be used.
- null|int|\\DateInterval `$defaultTtl` : Default Time to Live in secondes. By defaults 3600 secondes.

```
use LuFiipe\SimpleCache\Cache;

$cache = new Cache(__DIR__ . '/cache', 1800);

// Equivalent to:
$ttl = \DateInterval::createFromDateString('30 minutes');
$cache = new Cache(__DIR__ . '/cache', $ttl);
```

Retrieving items from the cache
-------------------------------

[](#retrieving-items-from-the-cache)

### Cache::get()

[](#cacheget)

The `get()` method retrieves items from the cache. If the item is not found, it returns `null`. Alternatively, you can provide a second argument to specify a default value to return when the item is missing.

```
use LuFiipe\SimpleCache\Cache;

$cache = new Cache();

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

$value = $cache->get('key', 'default');
```

### Cache::getMultiple()

[](#cachegetmultiple)

The `getMultiple()` method retrieves multiple cache items by their `keys`.

```
use LuFiipe\SimpleCache\Cache;

$cache = new Cache();
$value = $cache->getMultiple(['key1', 'key2', 'key3']);
```

Like the `get()` method, you may pass a second argument to specifying the default value you wish to be returned if the item doesn't exist.

```
use LuFiipe\SimpleCache\Cache;

$cache = new Cache();
$cache->set('key1', 'value');

$value = $cache->getMultiple(['key1', 'badkey'], 'default');
```

The above example will output:

```
array(2) {
  [key1] => string(5) "value",
  [badkey] => string(7) "default",
}

```

Storing items in the cache
--------------------------

[](#storing-items-in-the-cache)

### Cache::set()

[](#cacheset)

The `set()` method store items in the cache. If the storage time is not passed to the `set()` method, the item will be stored using the cache instance's default TTL (by defaults 3600 secondes). Instead of passing the number of seconds as an `integer`, you may also pass a `DateInterval` instance representing the desired expiration time of the cached item.

```
use LuFiipe\SimpleCache\Cache;

$cache = new Cache();
$cache->set('key', 'value');

$cache->set('key', 'value', 28800);
$cache->set('key', 'value', new \DateInterval('PT8H'))
```

### Cache::setMultiple()

[](#cachesetmultiple)

`setMultiple()` is similar to `set()`, but instead of a single key/value item, it works on multiple items. The expiration time applies to all the items at once.

```
use LuFiipe\SimpleCache\Cache;

$cache = new Cache();
$cache->setMultiple([
    'key1' => 'value1',
    'key2' => 'value2',
]);

$cache->set('key', 'value', 28800);
$cache->set('key', 'value', new \DateInterval('PT8H'));
```

Removing items from the cache
-----------------------------

[](#removing-items-from-the-cache)

### Cache::delete()

[](#cachedelete)

You can delete items from the cache using the `delete()` method.

```
use LuFiipe\SimpleCache\Cache;

$cache = new Cache();

$cache->delete('key1');
```

### Cache::deleteMultiple()

[](#cachedeletemultiple)

The `deleteMultiple()` method removes multiple cache items at once using a list of keys.

```
use LuFiipe\SimpleCache\Cache;

$cache = new Cache();

$cache->deleteMultiple(['key1', 'key2']);
```

### Cache::clear()

[](#cacheclear)

You can clear the entire cache with the `clear()` method.

```
use LuFiipe\SimpleCache\Cache;

$cache = new Cache();

$cache->clear();
```

Checking if an item exists
--------------------------

[](#checking-if-an-item-exists)

The `has()` method checks whether an item exists in the cache. If the item is not found, it will return `false`.

```
use LuFiipe\SimpleCache\Cache;

$cache = new Cache();

if ($cache->has('key')) {
    // ...
}
```

Tests
-----

[](#tests)

By default, during testing, the cache uses the OS temporary files directory. To use a specific directory, copy the file `phpunit.xml.dist` to `phpunit.xml` and update the value of the `CACHE_DIR` variable.

Then, run:

```
php vendor/bin/phpunit

```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance53

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

327d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/28425e09c9ba3f962ef94ce3ecbe688e74e0c6254591bd9a35a45dcf6dfd5c98?d=identicon)[lufiipe](/maintainers/lufiipe)

---

Top Contributors

[![lufiipe](https://avatars.githubusercontent.com/u/7064120?v=4)](https://github.com/lufiipe "lufiipe (1 commits)")

---

Tags

phpfilesystemcache

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/lufiipe-simplecache/health.svg)

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

###  Alternatives

[voku/simple-cache

Simple Cache library

322.5M7](/packages/voku-simple-cache)

PHPackages © 2026

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