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

ActiveLibrary[Caching](/categories/caching)

micropackage/cache
==================

WordPress Cache wrapper with Object and Transient drivers

1.0.4(2y ago)1334.1k↓50%3MITPHPPHP &gt;=5.6CI failing

Since Jan 24Pushed 2y ago3 watchersCompare

[ Source](https://github.com/micropackage/cache)[ Packagist](https://packagist.org/packages/micropackage/cache)[ RSS](/packages/micropackage-cache/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (7)Used By (0)

Cache
=====

[](#cache)

[![BracketSpace Micropackage](https://camo.githubusercontent.com/7a9f5ff780f859fdebce60d4e11572de05f86c42ef96b77967c24d7ea7d1e04b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f427261636b657453706163652d4d6963726f7061636b6167652d627269676874677265656e)](https://bracketspace.com)[![Latest Stable Version](https://camo.githubusercontent.com/d3514dc26ef959a24cd858b563e2797031fbb93d4c1c0cda8332a6718636af2f/68747470733a2f2f706f7365722e707567782e6f72672f6d6963726f7061636b6167652f63616368652f762f737461626c65)](https://packagist.org/packages/micropackage/cache)[![PHP from Packagist](https://camo.githubusercontent.com/7501c8c2d8ed6c46ecb8735a9aa79d73e80ea5f6793cfc1ed1312a17ce0590c1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d6963726f7061636b6167652f63616368652e737667)](https://packagist.org/packages/micropackage/cache)[![Total Downloads](https://camo.githubusercontent.com/b9be96090f65dee9f44fb1fabd7a992af8e46e6fde1400cd8e946a6e3eb30edd/68747470733a2f2f706f7365722e707567782e6f72672f6d6963726f7061636b6167652f63616368652f646f776e6c6f616473)](https://packagist.org/packages/micropackage/cache)[![License](https://camo.githubusercontent.com/4093ccfdf6d0cece624cfb836ec9331509ae78264e45460ec376c080464dcafa/68747470733a2f2f706f7365722e707567782e6f72672f6d6963726f7061636b6167652f63616368652f6c6963656e7365)](https://packagist.org/packages/micropackage/cache)

 [![Micropackage logo](https://camo.githubusercontent.com/9b9fc4f221b3683db4f9cc63e1ed92220004bbda118206d0a26d5ce6377d4d46/68747470733a2f2f627261636b657473706163652e636f6d2f6578747261732f6d6963726f7061636b6167652f6d6963726f7061636b6167652d736d616c6c2e706e67)](https://camo.githubusercontent.com/9b9fc4f221b3683db4f9cc63e1ed92220004bbda118206d0a26d5ce6377d4d46/68747470733a2f2f627261636b657473706163652e636f6d2f6578747261732f6d6963726f7061636b6167652f6d6963726f7061636b6167652d736d616c6c2e706e67)

🧬 About Cache
-------------

[](#-about-cache)

This micropackage is a wrapper for WordPress cache with two drivers implemented:

- [WP Object Cache API](https://codex.wordpress.org/Class_Reference/WP_Object_Cache)
- [Transients API](https://codex.wordpress.org/Transients_API)

It provides a unified, object-oriented way to manipulate WordPress Cache, witch the Cache manipulator object for even easier setting and getting the cache.

💾 Installation
--------------

[](#-installation)

```
composer require micropackage/cache
```

🕹 Usage
-------

[](#-usage)

### Object Cache

[](#object-cache)

Constructing the Object Cache driver:

```
use Micropackage\Cache\Driver\ObjectCache;

$object_cache = new ObjectCache( $group = 'my_group', $expiration = DAY_IN_SECONDS );
$object_cache->set_key( 'cache_key' );
```

Group parameter allows you to store the cache under the same key across multiple groups. Default is empty string.

By default the expiration is set to `0` which means the transient never expires.

#### Available methods

[](#available-methods)

MethodDescriptionReturns`set_key( (string) $key )`Sets the cache key$this`get_key()`Gets the cache key(string) Cache key`set_group( (string) $group )`Sets the cache group$this`get_group`Gets the cache group(string) Default empty string`set_expiration( (int) $expiration )`Sets the cache expiration in seconds$this`get_expiration()`Gets the cache expiration(int) Expiration seconds
Default 0 which means the cache
doesn't expire`set( (mixed) $value )`Sets the cachevoid`add( (mixed) $value )`Sets the cache
only if it wasn't set beforevoid`get()`Gets the cached valuemixed|false
False if not set`force_get()`Gets the cached value
and updates the local cache
from persistent cachemixed|false
False if not set`delete()`Deletes the cachevoid### Transient Cache

[](#transient-cache)

Constructing the Transient Cache driver:

```
use Micropackage\Cache\Driver\Transient;

$transient_cache = new Transient( $expiration = DAY_IN_SECONDS );
$transient_cache->set_key( 'cache_key' );
```

By default the expiration is set to `0` which means the transient never expires.

#### Available methods

[](#available-methods-1)

MethodDescriptionReturns`set_key( (string) $key )`Sets the cache key$this`get_key()`Gets the cache key(string) Cache key`set_expiration( (int) $expiration )`Sets the cache expiration in seconds$this`get_expiration()`Gets the cache expiration(int) Expiration seconds
Default 0 which means the cache
 doesn't expire`set( (mixed) $value )`Sets the cachevoid`add( (mixed) $value )`Sets the cache only if it wasn't set beforevoid`get()`Gets the cached valuemixed|false
False if not set`delete()`Deletes the cachevoid### Cache manipulator

[](#cache-manipulator)

The Cache manipulator object allows you to use the `collect` method to easily get/store the cache value.

See the below example with Object Cache (you can pass the Transient Driver as well).

```
use Micropackage\Cache\Cache;
use Micropackage\Cache\Driver\ObjectCache;

$driver = new ObjectCache( $group = 'my_group', $expiration = DAY_IN_SECONDS );
$cache  = new Cache( $driver, $cache_key = 'extremaly_important_thing' );

$the_thing = $cache->collect( function() {
	return 'The value was not set apparently';
} );
```

The `collect` method takes a callable function as an argument. If the cache wasn't set for the key provided in cache construtor, the callable is called which should return the value for cache. The value is stored and returned.

Using variables from outside the callable:

```
$some_var = 'I am awesome!';

$the_thing = $cache->collect( function() use ( $some_var ) {
	return $some_var;
} );
```

📦 About the Micropackage project
--------------------------------

[](#-about-the-micropackage-project)

Micropackages - as the name suggests - are micro packages with a tiny bit of reusable code, helpful particularly in WordPress development.

The aim is to have multiple packages which can be put together to create something bigger by defining only the structure.

Micropackages are maintained by [BracketSpace](https://bracketspace.com).

📖 Changelog
-----------

[](#-changelog)

[See the changelog file](./CHANGELOG.md).

📃 License
---------

[](#-license)

This software is released under MIT license. See the [LICENSE](./LICENSE) file for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.5% 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 ~312 days

Total

5

Last Release

1057d ago

### Community

Maintainers

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

---

Top Contributors

[![jakubmikita](https://avatars.githubusercontent.com/u/18362490?v=4)](https://github.com/jakubmikita "jakubmikita (29 commits)")[![Dartui](https://avatars.githubusercontent.com/u/2657856?v=4)](https://github.com/Dartui "Dartui (2 commits)")

---

Tags

cache-drivercomposer-librarymicropackagewordpresswordpress-cache

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)[cheprasov/php-redis-client

Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 6.0

1281.2M21](/packages/cheprasov-php-redis-client)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)

PHPackages © 2026

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