PHPackages                             mitogh/on-cache-please - 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. mitogh/on-cache-please

ActiveLibrary[Caching](/categories/caching)

mitogh/on-cache-please
======================

Storage a request automatically on a transient cache

1.0.3(10y ago)016MITPHPPHP &gt;=5.4

Since Dec 27Pushed 10y ago2 watchersCompare

[ Source](https://github.com/mitogh/On-Cache-Please)[ Packagist](https://packagist.org/packages/mitogh/on-cache-please)[ Docs](https://github.com/mitogh/On-Cache-Please)[ RSS](/packages/mitogh-on-cache-please/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

On Cache Please [![Build Status](https://camo.githubusercontent.com/bffa4f3fe21729fff561a26067bbf3530b28d46b8ab631f9fba1ba037283315a/68747470733a2f2f7472617669732d63692e6f72672f6d69746f67682f4f6e2d43616368652d506c656173652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mitogh/On-Cache-Please)
=================================================================================================================================================================================================================================================================================================================

[](#on-cache-please-)

> Because programmers are to lazy to write repeated code, this utility automatically storages the data of a callback in a transient to faster access the next time the data is accessed.

Description
-----------

[](#description)

This utility can help you to create faster cache storage of expensive external request or hard work into the DB to faster access the next time, to retrive the value from a cache rather than the function, this library make uses of [transient api](https://codex.wordpress.org/Transients_API) to save the data from the requests into the DB.

Requirements.
-------------

[](#requirements)

- WordPress
- PHP 5.4 &gt;=

Installation.
-------------

[](#installation)

The easiest way to install this library is using composer, in order to add this library as a dependency for your composer file you only need to run in your terminal:

```
composer require mitogh/on-cache-please
```

To retrive the library from [packagist](https://packagist.org/packages/mitogh/on-cache-please). This will add the on-cache-please library as a dependency in your `composer.json`file.

The other way is directly include the file:

```
include 'On-Cache-Please/src/OnCache.php';
```

Into your `functions.php` file in your theme or in your plugin.

Methods and Properties
----------------------

[](#methods-and-properties)

Here are listed only the public methods that are available to be used from the outside of the library.

### OnCache::please

[](#oncacheplease)

This static method is the public way to storaged the data from a function in a transient by a determined amount of time in order to decrease the number of request and download time.

**Parameters**

You can pass an `array` of arguments to the method `please` in order to update some default values and some required params as well.

- `name` *(string)* - required. This is a required param since we need a value to identify the transient, where the data is going to be stored.
- `callback` *(string|function)* - required. The function or name of the function to execute, in this function you can do expensive things like an http external request or a instagram API call, just make sure to return the data you want to save on the cache, the returned value will be storead in the transient.
- `duration` *(int)* - optional. 1 hour by default. This value can be any integer number and represents the life of the transient in seconds before execute the `callback` again and update the transient, there are few [few already defined](https://codex.wordpress.org/Transients_API#Using_Time_Constants). constants that migh help you.

**Example**

In this example we retrieve the data from `http://codepen.io/jobs.json`and store the result in a transient that has a duration (by default of 1 hour), so the next hour we are going to have the latest updated data wiouth having to make a request every time the page is loaded.

Library installed via `composer.json`

```
include './vendor/autoload.php';
$args = array(
    'name' => 'codepen_jobs',
	'callback' => function(){
		$url = 'http://codepen.io/jobs.json';
		return wp_remote_retrieve_body( wp_remote_get( $url ) );
	},
);
$jobs = mitogh\OnCache::please( $args );
```

Library installed manually:

```
include './On-Cache-Please/src/OnCache.php';
$args = array(
    'name' => 'codepen_jobs',
	'callback' => function(){
		$url = 'http://codepen.io/jobs.json';
		return wp_remote_retrieve_body( wp_remote_get( $url ) );
	},
);
$jobs = mitogh\OnCache::please( $args );
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

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

Total

4

Last Release

3766d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.5

1.0.3PHP &gt;=5.4

### Community

Maintainers

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

---

Top Contributors

[![mitogh](https://avatars.githubusercontent.com/u/3921289?v=4)](https://github.com/mitogh "mitogh (45 commits)")

---

Tags

requestwordpresscache

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mitogh-on-cache-please/health.svg)

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

###  Alternatives

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

PHPackages © 2026

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