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

ActiveLibrary[Caching](/categories/caching)

helick/cache-helpers
====================

Helpers for the WordPress object cache and transients

v1.1.0(6y ago)1391MITPHPPHP &gt;=7.1

Since Jun 26Pushed 6y agoCompare

[ Source](https://github.com/helick/cache-helpers)[ Packagist](https://packagist.org/packages/helick/cache-helpers)[ RSS](/packages/helick-cache-helpers/feed)WikiDiscussions master Synced 3d ago

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

Helick Cache Helpers
====================

[](#helick-cache-helpers)

Helpers for the WordPress object cache and transients.

[![Latest Version on Packagist](https://camo.githubusercontent.com/7a57190a28bcebecacbf49fc9f127d961bfc5d2adb926579fd21fdce97c239cc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68656c69636b2f63616368652d68656c706572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/helick/cache-helpers)[![Total Downloads](https://camo.githubusercontent.com/4f21b29e115213330d481d138ce73c90f674c676d2a1b89929474d3a93ddeb78/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68656c69636b2f63616368652d68656c706572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/helick/cache-helpers)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Quality Score](https://camo.githubusercontent.com/5e1efb5d7877e67dc3d098f52440a3d3ded63ab3ad1ec81b3b3e13e2c2433d40/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f68656c69636b2f63616368652d68656c706572732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/helick/cache-helpers)

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

[](#requirements)

Make sure all dependencies have been installed before moving on:

- [PHP](http://php.net/manual/en/install.php) &gt;= 7.1
- [Composer](https://getcomposer.org/download/)

Install
-------

[](#install)

Via Composer:

```
$ composer require helick/cache-helpers
```

Usage
-----

[](#usage)

The package provides the following functions for WordPress:

- [`cache_remember()`](#cache_remember)
- [`cache_forget()`](#cache_forget)
- [`transient_remember()`](#transient_remember)
- [`transient_forget()`](#transient_forget)
- [`site_transient_remember()`](#site_transient_remember)
- [`site_transient_forget()`](#site_transient_forget)

Each function checks the response of the callback for a `WP_Error` object, ensuring you're not caching temporary errors for long periods of time. PHP Exceptions will also not be cached.

### cache\_remember()

[](#cache_remember)

Get a value from the object cache, if one doesn't exist, run the given callback to generate and cache the value.

#### Parameters

[](#parameters)

 (string) $key The cache key. (callable) $callback The callback used to generate and cache the value. (string) $group Optional. The cache group. Default is empty. (int) $expire Optional. The number of seconds before the cache entry should expire. Default is 0 (as long as possible).#### Example

[](#example)

```
use function Helick\CacheHelpers\cache_remember;

function get_latest_posts()
{
    return cache_remember('latest', function () {
        return new WP_Query([
            'posts_per_page' => 5,
            'orderby'        => 'post_date',
            'order'          => 'desc',
        ]);
    }, 'posts', HOUR_IN_SECONDS);
}
```

### cache\_forget()

[](#cache_forget)

Get and subsequently delete a value from the object cache.

#### Parameters

[](#parameters-1)

 (string) $key The cache key. (string) $group Optional. The cache group. Default is empty. (mixed) $default Optional. The default value to return if the given key doesn't exist in the object cache. Default is null.#### Example

[](#example-1)

```
use function Helick\CacheHelpers\cache_forget;

function display_error_message()
{
    $error_message = cache_forget('form_errors', 'my-cache-group', false);

    if ($error_message) {
        echo 'An error occurred: ' . $error_message;
    }
}
```

### transient\_remember()

[](#transient_remember)

Get a value from the transients, if one doesn't exist, run the given callback to generate and cache the value.

#### Parameters

[](#parameters-2)

 (string) $key The cache key. (callable) $callback The callback used to generate and cache the value. (int) $expire Optional. The number of seconds before the cache entry should expire. Default is 0 (as long as possible).#### Example

[](#example-2)

```
use function Helick\CacheHelpers\transient_remember;

function get_tweets()
{
    $user_id = get_current_user_id();
    $key     = 'latest_tweets_' . $user_id;

    return transient_remember($key, function () use ($user_id) {
        return get_latest_tweets_for_user($user_id);
    }, 15 * MINUTE_IN_SECONDS);
}
```

### transient\_forget()

[](#transient_forget)

Get and subsequently delete a value from the transients.

#### Parameters

[](#parameters-3)

 (string) $key The cache key. (mixed) $default Optional. The default value to return if the given key doesn't exist in transients. Default is null.```
use function Helick\CacheHelpers\transient_forget;

function display_error_message()
{
    $error_message = transient_forget('form_errors', false);

    if ($error_message) {
        echo 'An error occurred: ' . $error_message;
    }
}
```

### site\_transient\_remember()

[](#site_transient_remember)

Get a value from the transients, if one doesn't exist, run the given callback to generate and cache the value.

This function shares arguments and behavior with [`transient_remember()`](#transient_remember), but works network-wide when using WordPress Multisite.

#### Parameters

[](#parameters-4)

 (string) $key The cache key. (mixed) $default Optional. The default value to return if the given key doesn't exist in transients. Default is null.```
use function Helick\CacheHelpers\site_transient_remember;

function get_tweets()
{
    $user_id = get_current_user_id();
    $key     = 'latest_tweets_' . $user_id;

    return site_transient_remember($key, function () use ($user_id) {
        return get_latest_tweets_for_user($user_id);
    }, 15 * MINUTE_IN_SECONDS);
}
```

### site\_transient\_forget()

[](#site_transient_forget)

Get and subsequently delete a value from the site transients.

This function shares arguments and behavior with [`transient_forget()`](#transient_forget), but works network-wide when using WordPress Multisite.

#### Parameters

[](#parameters-5)

 (string) $key The cache key. (mixed) $default Optional. The default value to return if the given key doesn't exist in transients. Default is null.```
use function Helick\CacheHelpers\site_transient_forget;

function display_error_message()
{
    $error_message = site_transient_forget('form_errors', false);

    if ($error_message) {
        echo 'An error occurred: ' . $error_message;
    }
}
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Evgenii Nasyrov](https://github.com/nasyrov)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

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

Total

2

Last Release

2479d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d5180ba0cd30309ada4562457c6337069906fea97f827f1c24b82fddb1bdc9a?d=identicon)[nasyrov](/maintainers/nasyrov)

---

Tags

composercomposer-librarywordpresswordpresshelperscachehelick

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[markjaquith/wp-tlc-transients

A WP transients interface with support for soft-expiration, background updating of the transients.

34175.3k3](/packages/markjaquith-wp-tlc-transients)[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.

23817.0k1](/packages/rtcamp-nginx-helper)[rarst/fragment-cache

WordPress plugin for partial and async caching of heavy front-end elements.

14115.0k2](/packages/rarst-fragment-cache)

PHPackages © 2026

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