PHPackages                             davidecesarano/embryo-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. davidecesarano/embryo-cache

ActiveLibrary[Caching](/categories/caching)

davidecesarano/embryo-cache
===========================

PSR-16 Simple Cache implementantion using PSR Stream.

1.0.1(5y ago)112111MITPHPPHP &gt;=7.1

Since Nov 8Pushed 5y ago1 watchersCompare

[ Source](https://github.com/davidecesarano/Embryo-Cache)[ Packagist](https://packagist.org/packages/davidecesarano/embryo-cache)[ Docs](https://github.com/davidecesarano/embryo-cache)[ RSS](/packages/davidecesarano-embryo-cache/feed)WikiDiscussions master Synced 2mo ago

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

Embryo Cache
============

[](#embryo-cache)

A minimal PSR-16 cache implementation with file stream system.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.1
- A [PSR-7](https://www.php-fig.org/psr/psr-7/) http message implementation and [PSR-17](https://www.php-fig.org/psr/psr-17/) http factory implementation (ex. [Embryo-Http](https://github.com/davidecesarano/embryo-http))
- A PSR response emitter (ex. [Embryo-Emitter](https://github.com/davidecesarano/Embryo-Emitter))

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

[](#installation)

Using Composer:

```
$ composer require davidecesarano/embryo-cache

```

Usage
-----

[](#usage)

Set `Response` and `Emitter` objects. Later, set the `Cache` object passing it the cache directory path.

```
use Embryo\Cache\Cache;
use Embryo\Http\Emitter\Emitter;
use Embryo\Http\Factory\ResponseFactory;

$emitter   = new Emitter;
$response  = (new ResponseFactory)->createResponse(200);
$cachePath = __DIR__.DIRECTORY_SEPARATOR.'cache';
$cache     = new Cache($cachePath);

if (!$cache->has('test')) {
    $cache->set('test', 'Hello World!', 3600);
}

$body = $response->getBody();
$body->write($cache->get('test', 'Default value!'));
$response = $response->withBody($body);

$emitter->emit($response);
```

In this example we check if the item cache `test` exists; if it not exists, we set `test` item cache with value `Hello World!` and the Time To Live (TTL) in `3600` seconds. Later, we get the `test` item cache with default value if item cache not exists.

### Example

[](#example)

You may quickly test this using the built-in PHP server going to .

```
$ cd example
$ php -S localhost:8000

```

Options
-------

[](#options)

### `setDefaultTtl($ttl)`

[](#setdefaultttlttl)

You can set the default expiration TTL time. `$ttl` must be an integer or a `DateInterval` object.

Collection
----------

[](#collection)

### Retrieving data

[](#retrieving-data)

You may retrieve an item from the cache and you may also pass a default value as the second argument to the `get` method:

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

### Storing data

[](#storing-data)

The `set` method may be used to set a new value onto a cache with an optional expiration TTL time:

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

### Deleting data

[](#deleting-data)

The `delete` method will remove a piece of data from the cache. If you would like the remove all data from the cache, you may use the `clear` method:

```
$cache->delete('key');
$cache->clear();
```

### Retrieving multiple data

[](#retrieving-multiple-data)

You may retrieve multiple items from the cache and you may also pass a default value as the second argument to the `getMultiple` method:

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

### Storing multiple data

[](#storing-multiple-data)

The `setMultiple` method may be used to set a multiple values onto a cache with an optional expiration TTL time:

```
$cache->setMultiple([
    'key1' => 'value',
    'key2' => 'value'
], 3600);
```

### Deleting multiple data

[](#deleting-multiple-data)

The `deleteMultiple` method will remove items from the cache:

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

### Determining if an item exists in the cache

[](#determining-if-an-item-exists-in-the-cache)

To determine if an item is present in the cache, you may use the `has` method. The has method returns `true` if the item is present and is not `false`:

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

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

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

Every ~61 days

Total

2

Last Release

1948d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16277144?v=4)[Davide Cesarano](/maintainers/davidecesarano)[@davidecesarano](https://github.com/davidecesarano)

---

Top Contributors

[![davidecesarano](https://avatars.githubusercontent.com/u/16277144?v=4)](https://github.com/davidecesarano "davidecesarano (10 commits)")

---

Tags

cachephpphp7psr-16phpcachepsr-16

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[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)

PHPackages © 2026

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