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

ActiveLibrary[Caching](/categories/caching)

fyre/cache
==========

A cache library.

v6.0.1(7mo ago)0460↓87.5%4MITPHP

Since Oct 31Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/elusivecodes/FyreCache)[ Packagist](https://packagist.org/packages/fyre/cache)[ RSS](/packages/fyre-cache/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (10)Dependencies (9)Versions (56)Used By (4)

FyreCache
=========

[](#fyrecache)

**FyreCache** is a free, open-source cache library for *PHP*.

Table Of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Methods](#methods)
- [Cachers](#cachers)
    - [File](#file)
    - [Memcached](#memcached)
    - [Redis](#redis)

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

[](#installation)

**Using Composer**

```
composer require fyre/cache

```

In PHP:

```
use Fyre\Cache\CacheManager;
```

Basic Usage
-----------

[](#basic-usage)

- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).
- `$config` is a [*Config*](https://github.com/elusivecodes/FyreConfig).

```
$cacheManager = new CacheManager($container);
```

Default configuration options will be resolved from the "*Cache*" key in the [*Config*](https://github.com/elusivecodes/FyreConfig).

The cache will be disabled by default if the `"*App.debug*" key is set in the [*Config*](https://github.com/elusivecodes/FyreConfig).

**Autoloading**

It is recommended to bind the *CacheManager* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.

```
$container->singleton(CacheManager::class);
```

Any dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).

```
$cacheManager = $container->use(CacheManager::class);
```

Methods
-------

[](#methods)

**Build**

Build a [*Cacher*](#cachers).

- `$options` is an array containing configuration options.

```
$cacher = $cacheManager->build($options);
```

[*Cacher*](#cachers) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).

**Clear**

Clear all instances and configs.

```
$cacheManager->clear();
```

**Disable**

Disable the cache.

```
$cacheManager->disable();
```

If the cache is disabled, the `use` method will always return a *NullCacher*.

**Enable**

Enable the cache.

```
$cacheManager->enable();
```

**Get Config**

Get a [*Cacher*](#cachers) config.

- `$key` is a string representing the [*Cacher*](#cachers) key.

```
$config = $cacheManager->getConfig($key);
```

Alternatively, if the `$key` argument is omitted an array containing all configurations will be returned.

```
$config = $cacheManager->getConfig();
```

**Has Config**

Determine whether a [*Cacher*](#cachers) config exists.

- `$key` is a string representing the [*Cacher*](#cachers) key, and will default to `CacheManager::DEFAULT`.

```
$hasConfig = $cacheManager->hasConfig($key);
```

**Is Enabled**

Determine whether the cache is enabled.

```
$cacheManager->isEnabled();
```

**Is Loaded**

Determine whether a [*Cacher*](#cachers) instance is loaded.

- `$key` is a string representing the [*Cacher*](#cachers) key, and will default to `CacheManager::DEFAULT`.

```
$isLoaded = $cacheManager->isLoaded($key);
```

**Set Config**

Set the [*Cacher*](#cachers) config.

- `$key` is a string representing the [*Cacher*](#cachers) key.
- `$options` is an array containing configuration options.

```
$cacheManager->setConfig($key, $options);
```

**Unload**

Unload a [*Cacher*](#cachers).

- `$key` is a string representing the [*Cacher*](#cachers) key, and will default to `CacheManager::DEFAULT`.

```
$cacheManager->unload($key);
```

**Use**

Load a shared [*Cacher*](#cachers) instance.

- `$key` is a string representing the [*Cacher*](#cachers) key, and will default to `CacheManager::DEFAULT`.

```
$cacher = $cacheManager->use($key);
```

[*Cacher*](#cachers) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).

Cachers
-------

[](#cachers)

You can load a specific cacher by specifying the `className` option of the `$options` variable above.

Custom cachers can be created by extending `\Fyre\Cache\Cacher`, ensuring all below methods are implemented.

**Clear**

Clear the cache.

```
$cleared = $cacher->clear();
```

**Decrement**

Decrement a cache value.

- `$key` is a string representing the cache key.
- `$amount` is a number indicating the amount to decrement by, and will default to *1*.

```
$value = $cacher->decrement($key, $amount);
```

**Delete**

Delete an item from the cache.

- `$key` is a string representing the cache key.

```
$deleted = $cacher->delete($key);
```

**Delete Multiple**

Delete multiple items from the cache.

- `$keys` is an array containing the cache keys.

```
$deleted = $cacher->deleteMultiple($keys);
```

**Get**

Retrieve a value from the cache.

- `$key` is a string representing the cache key.
- `$default` is the default value to return, and will default to *null*.

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

**Get Multiple**

Retrieve multiple values from the cache.

- `$keys` is an array containing the cache keys.
- `$default` is the default value to return, and will default to *null*.

```
$values = $cacher->getMultiple($keys, $default);
```

**Has**

Determine whether an item exists in the cache.

- `$key` is a string representing the cache key.

```
$has = $cacher->has($key);
```

**Increment**

Increment a cache value.

- `$key` is a string representing the cache key.
- `$amount` is a number indicating the amount to increment by, and will default to *1*.

```
$value = $cacher->increment($key, $amount);
```

**Remember**

Retrieve an item from the cache, or save a new value if it doesn't exist.

- `$key` is a string representing the cache key.
- `$callback` is the callback method to generate the value.
- `$expire` is a number indicating the number of seconds the value will be valid, and will default to *null*.

```
$value = $cacher->remember($key, $callback, $expire);
```

**Set**

Set an item in the cache.

- `$key` is a string representing the cache key.
- `$value` is the value to save in the cache.
- `$expire` is a number indicating the number of seconds the value will be valid, and will default to *null*.

```
$saved = $cacher->set($key, $value, $expire);
```

**Set Multiple**

Set multiple items in the cache.

- `$values` is an array containing the values to save in the cache.
- `$expire` is a number indicating the number of seconds the value will be valid, and will default to *null*.

```
$saved = $cacher->setMultiple($values, $expire);
```

**Size**

Get the size of the cache.

```
$size = $cacher->size();
```

Array
-----

[](#array)

The Array cacher can be loaded using customer configuration.

- `$options` is an array containing configuration options.
    - `className` must be set to `\Fyre\Cache\Handlers\ArrayCacher`.
    - `expire` is a number indicating the default cache timeout.

```
$container->use(Config::class)->set('Cache.array', $options);
```

### File

[](#file)

The File cacher can be loaded using custom configuration.

- `$options` is an array containing configuration options.
    - `className` must be set to `\Fyre\Cache\Handlers\FileCacher`.
    - `expire` is a number indicating the default cache timeout.
    - `prefix` is a string representing the cache key prefix.
    - `path` is a string representing the directory path, and will default to "*/tmp/cache*".
    - `mode` is a number indicating the cache file permissions, and will default to *0640*.

```
$container->use(Config::class)->set('Cache.file', $options);
```

### Memcached

[](#memcached)

The Memcached cacher can be loaded using custom configuration.

- `$options` is an array containing configuration options.
    - `className` must be set to `\Fyre\Cache\Handlers\MemcachedCacher`.
    - `expire` is a number indicating the default cache timeout.
    - `prefix` is a string representing the cache key prefix.
    - `host` is a string representing the Memcached host, and will default to "*127.0.0.1*".
    - `port` is a number indicating the Memcached port, and will default to *11211*.
    - `weight` is a number indicating the server weight, and will default to *1*.

```
$container->use(Config::class)->set('Cache.memcached', $options);
```

### Redis

[](#redis)

The Redis cacher can be loaded using custom configuration.

- `$options` is an array containing configuration options.
    - `className` must be set to `\Fyre\Cache\Handlers\RedisCacher`.
    - `expire` is a number indicating the default cache timeout.
    - `prefix` is a string representing the cache key prefix.
    - `host` is a string representing the Redis host, and will default to "*127.0.0.1*".
    - `password` is a string representing the Redis password.
    - `port` is a number indicating the Redis port, and will default to *6379*.
    - `database` is a string representing the Redis database.
    - `timeout` is a number indicating the connection timeout.
    - `persist` is a boolean indicating whether to use a persistent connection, and will default to *true*.
    - `tls` is a boolean indicating whether to use a tls connection, and will default to *true*.
    - `ssl` is an array containing SSL options.
        - `key` is a string representing the path to the key file.
        - `cert` is a string representing the path to the certificate file.
        - `ca` is a string representing the path to the certificate authority file.

```
$container->use(Config::class)->set('Cache.redis', $options);
```

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance62

Regular maintenance activity

Popularity12

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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 ~27 days

Total

55

Last Release

233d ago

Major Versions

v1.1.7 → v2.02023-07-21

v2.0.1 → v3.02023-07-23

v3.0.11 → v4.02024-10-31

v4.0.2 → v5.02024-11-02

v5.3.5 → v6.02025-10-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/fad81fd5941e3a637c8a5749d05ae3ed9314d5e2fee57f59c3d9ec3b41259c6b?d=identicon)[elusivecodes](/maintainers/elusivecodes)

---

Top Contributors

[![elusivecodes](https://avatars.githubusercontent.com/u/18050480?v=4)](https://github.com/elusivecodes "elusivecodes (36 commits)")

---

Tags

cachememcachedphpredis

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[moonshine/moonshine

Laravel administration panel

1.3k239.9k75](/packages/moonshine-moonshine)[laminas/laminas-cache

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

1067.2M145](/packages/laminas-laminas-cache)[sabre/cache

Simple cache abstraction layer implementing PSR-16

551.3M4](/packages/sabre-cache)[voku/simple-cache

Simple Cache library

322.6M9](/packages/voku-simple-cache)[graham-campbell/bounded-cache

A Bounded TTL PSR-16 Cache Implementation

112.1M10](/packages/graham-campbell-bounded-cache)[neos/cache

Neos Cache Framework

102.1M36](/packages/neos-cache)

PHPackages © 2026

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