PHPackages                             mouf/utils.cache.cache-interface - 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. mouf/utils.cache.cache-interface

ActiveMouf-library[Caching](/categories/caching)

mouf/utils.cache.cache-interface
================================

This package only contains the interface that must be implemented by caching classes. Unless you want to implement your own caching method, you should import a cache package that will use this interface. For instance, common.utils.session-cache, or common.utils.file-cache.

v2.1.0(7y ago)0378.8k↓33.3%1[1 issues](https://github.com/thecodingmachine/utils.cache.cache-interface/issues)10MITPHPPHP &gt;=5.3.0

Since Oct 29Pushed 7y ago7 watchersCompare

[ Source](https://github.com/thecodingmachine/utils.cache.cache-interface)[ Packagist](https://packagist.org/packages/mouf/utils.cache.cache-interface)[ Docs](https://github.com/thecodingmachine/utils.cache.cache-interface)[ RSS](/packages/mouf-utilscachecache-interface/feed)WikiDiscussions 2.1 Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (5)Used By (10)

Mouf Cache system
=================

[](#mouf-cache-system)

The Mouf framework is only an IOC framework. As such, it does not provide any means for managing any kind of cache. Hopefully, the Mouf team provides also a range of packages to manage the caching of objects.

The cache architecture
----------------------

[](#the-cache-architecture)

Mouf provides several implementations of caching, and you can provide your own if you want. Each cache mechanism must just extend the `CacheInterface` interface that is part of the package utils/cache/cacheinterface.

By default, Mouf provides these caches:

- **FileCache**: a cache that writes cached elements in files, in a temporary folder.
- **SessionCache**: a cache that writes cached elements in the session of the current user. Therefore, this cache is local to a user.
- **ApcCache**: a cache that uses the APC extension to store data.
- **NoCache**: a cache that... does not provide any cache. Can be useful for development purpose.

The cache methods
-----------------

[](#the-cache-methods)

Each class implementing the CacheInterface provides simple methods to get and set data in the cache:

```
interface CacheInterface {
	/**
	 * Returns the cached value for the key passed in parameter.
	 *
	 * @param string $key
	 * @return mixed
	 */
	function get($key);

	/**
	 * Sets the value in the cache.
	 *
	 * @param string $key The key of the value to store
	 * @param mixed $value The value to store
	 * @param int $timeToLive The time to live of the cache, in seconds.
	 */
	function set($key, $value, $timeToLive = null);

	/**
	 * Removes the object whose key is $key from the cache.
	 *
	 * @param string $key The key of the object
	 */
	function purge($key);

	/**
	 * Removes all the objects from the cache.
	 *
	 */
	function purgeAll();
}
```

For instance, to store some value in the cache, you just need to write:

```
$cache->set("mykey", "myvalue", 15);
```

This will store the value "myvalue" in the cache, with key "mykey". The value will be stored for 15 seconds. If within 15 seconds, we perform a call to retrieve the cache, the value will be retrieved:

```
// Will print "myvalue" if called within 15 seconds.
echo $cache->get("mykey");
```

The third parameter is optional. If not passed, the default value will be used. The default value is "forever", which means the cached value will never time out. The default value can be overidden in the Mouf cache instance properties.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity61

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

Total

5

Last Release

2890d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1104771?v=4)[mouf](/maintainers/mouf)[@Mouf](https://github.com/Mouf)

---

Top Contributors

[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (20 commits)")

---

Tags

interfacecachemouf

### Embed Badge

![Health badge](/badges/mouf-utilscachecache-interface/health.svg)

```
[![Health](https://phpackages.com/badges/mouf-utilscachecache-interface/health.svg)](https://phpackages.com/packages/mouf-utilscachecache-interface)
```

###  Alternatives

[psr/simple-cache

Common interfaces for simple caching

8.1k727.3M2.1k](/packages/psr-simple-cache)[psr/cache

Common interface for caching libraries

5.2k686.9M1.3k](/packages/psr-cache)[amnuts/opcache-gui

A clean, effective and responsive interface for Zend OPcache, with real(ish)-time monitoring, filtering and the ability to invalidate files

1.3k4.6M14](/packages/amnuts-opcache-gui)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[beste/in-memory-cache

A PSR-6 In-Memory cache that can be used as a fallback implementation and/or in tests.

2512.2M6](/packages/beste-in-memory-cache)[rtcamp/nginx-helper

Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also provides cloudflare edge cache purging with Cache-Tags.

23517.0k1](/packages/rtcamp-nginx-helper)

PHPackages © 2026

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