PHPackages                             dimadin/wp-temporary - 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. dimadin/wp-temporary

ActiveLibrary[Caching](/categories/caching)

dimadin/wp-temporary
====================

WordPress library to cache data to the database. Like transients without object cache.

1.0.0(7y ago)32254GPL-2.0-or-laterPHPPHP &gt;=5.2.4

Since Sep 14Pushed 7y ago1 watchersCompare

[ Source](https://github.com/dimadin/wp-temporary)[ Packagist](https://packagist.org/packages/dimadin/wp-temporary)[ Docs](https://github.com/dimadin/wp-temporary)[ RSS](/packages/dimadin-wp-temporary/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (4)

WP\_Temporary
=============

[](#wp_temporary)

[![Build Status](https://camo.githubusercontent.com/c2ab0530a8bbba2d63f6ee20ca0267c0171b10f440fe882376fc84699c4a6ae1/68747470733a2f2f7777772e7472617669732d63692e6f72672f64696d6164696e2f77702d74656d706f726172792e7376673f6272616e63683d6d6173746572)](https://www.travis-ci.org/dimadin/wp-temporary)[![Latest Stable Version](https://camo.githubusercontent.com/cc8cfbb974ecef454d135382ff9379d7d9ed93b84fb1b689bccd9df15d8cc4fa/68747470733a2f2f706f7365722e707567782e6f72672f64696d6164696e2f77702d74656d706f726172792f76657273696f6e)](https://packagist.org/packages/dimadin/wp-temporary)

`WP_Temporary` is a helper class with a group of static methods that are used the same way as counterpart transient functions for storing data in the database until they expire. Basically, it's the same as when transient is stored in the database (with object cache disabled) so it isn't deleted until it expires.

Transients use object cache if it's available and only fallback to the database if it's not. Because of that, transients might disappear at any time before their expiration. `WP_Temporary` solves this because data stored with it does not disappear until it expires.

Additionally, `WP_Temporary` has a separate method that changes value of already set temporary data, but without changing expiration time of that data. This is different from transients that only allow setting of data that always changes expiration time so it start counting from the moment of setting.

`WP_Temporary` has built-in garbage collector and WP-CLI command.

Using
-----

[](#using)

`WP_Temporary` is available as Composer package that you can use in your project.

```
composer require dimadin/wp-temporary
```

Alternately, you can download file `class-wp-temporary.php` and include it in your project.

API
---

[](#api)

Full code reference is available at

### WP\_Temporary::set()

[](#wp_temporaryset)

Equivalent of [`set_transient()`](https://developer.wordpress.org/reference/functions/set_transient/).

### WP\_Temporary::get()

[](#wp_temporaryget)

Equivalent of [`get_transient()`](https://developer.wordpress.org/reference/functions/get_transient/).

### WP\_Temporary::delete()

[](#wp_temporarydelete)

Equivalent of [`delete_transient()`](https://developer.wordpress.org/reference/functions/delete_transient/).

### WP\_Temporary::update()

[](#wp_temporaryupdate)

This method is identical to `WP_Temporary::set()` with one difference: if temporary already exists, it will not change expiration time, just change its value (without using third parameter `$expiration`); if it doesn't exist, it will fallback to `WP_Temporary::set()`.

### WP\_Temporary::set\_site()

[](#wp_temporaryset_site)

Equivalent of [`set_site_transient()`](https://developer.wordpress.org/reference/functions/set_site_transient/).

### WP\_Temporary::get\_site()

[](#wp_temporaryget_site)

Equivalent of [`get_site_transient()`](https://developer.wordpress.org/reference/functions/get_site_transient/).

### WP\_Temporary::delete\_site()

[](#wp_temporarydelete_site)

Equivalent of [`delete_site_transient()`](https://developer.wordpress.org/reference/functions/delete_site_transient/).

### WP\_Temporary::update\_site()

[](#wp_temporaryupdate_site)

This method is identical to `WP_Temporary::set_site()` with one difference: if temporary already exists, it will not change expiration time, just change its value (without using third parameter `$expiration`); if it doesn't exist, it will fallback to `WP_Temporary::set_site()`.

### WP\_Temporary::clean()

[](#wp_temporaryclean)

This is garbage collector for `WP_Temporary`. It cleans up database from all expired temporaries (whose expiration was more than one minute ago).

Note that it isn't run by default, you need to either call it in your code with

`WP_Temporary::clean();`

or hook it to some action. For example, this calls it once daily using WP Cron:

`add_action( 'wp_scheduled_delete', array( 'WP_Temporary', 'clean' ) );`

### WP\_Temporary::init\_wp\_cli()

[](#wp_temporaryinit_wp_cli)

This method that initializes WP-CLI command `wp temporary`. It isn't run by default, you need to either call it in your code with

`WP_Temporary::init_wp_cli();`

or hook it to some action. For example, this calls only when WP-CLI is initialized:

`add_action( 'cli_init', array( 'WP_Temporary', 'init_wp_cli' ) );`

Note that if you are not using Composer for including `WP_Temporary()`, you must manually include file `/cli/Temporary_Command.php`.

WP-CLI
------

[](#wp-cli)

`WP_Temporary` implements the following commands:

### wp temporary

[](#wp-temporary)

Adds, gets, updates, and deletes temporary data.

The temporary data uses the WordPress database to persist values between requests. On a single site installation, values are stored in the `wp_options` table. On a multisite installation, values are stored in the `wp_options` or the `wp_sitemeta` table, depending on use of the `--network` flag.

**EXAMPLES**

```
# Set temporary.
$ wp temporary set sample_key "test data" 3600
Success: Temporary added.

# Update temporary.
$ wp temporary update sample_key "test data" 3600
Success: Temporary updated.

# Get temporary.
$ wp temporary get sample_key
test data

# Get all temporaries.
$ wp temporary get --all

# Delete temporary.
$ wp temporary delete sample_key
Success: Temporary deleted.

# Delete all temporaries.
$ wp temporary delete --all
Success: 14 temporaries deleted from the database.

```

#### wp temporary get

[](#wp-temporary-get)

Get a temporary value.

```
wp temporary get [] [--format=] [--network] [--all]

```

**OPTIONS**

```
[]
    Key for the temporary.

[--format=]
    Render output in a particular format.
    ---
    options:
      - json
      - yaml
    ---

[--network]
     Get the value of a network|site temporary.

[--all]
    Get all temporaries.

```

**EXAMPLES**

```
# Get temporary.
$ wp temporary get sample_key
test data

# Get temporary.
$ wp temporary get random_key
Warning: Temporary with key "random_key" is not set.

# Get all temporaries.
$ wp temporary get --all

```

#### wp temporary set

[](#wp-temporary-set)

Set a temporary value.

```
wp temporary set   [] [--network]

```

**OPTIONS**

```

    Key for the temporary.

    Value to be set for the temporary.

[]
    Time until expiration, in seconds.

[--network]
     Set the value of a network|site temporary.

```

**EXAMPLES**

```
$ wp temporary set sample_key "test data" 3600
Success: Temporary added.

```

#### wp temporary update

[](#wp-temporary-update)

Update a temporary value.

Change value of existing temporary without affecting expiration, or set new temporary with provided expiration if temporary doesn't exist.

```
wp temporary update   [] [--network]

```

**OPTIONS**

```

    Key for the temporary.

    Value to be set for the temporary.

[]
    Time until expiration, in seconds.

[--network]
     Set the value of a network|site temporary.

```

**EXAMPLES**

```
$ wp temporary update sample_key "test data" 3600
Success: Temporary updated.

```

#### wp temporary delete

[](#wp-temporary-delete)

Get a temporary value.

```
wp temporary delete [] [--network] [--all]

```

**OPTIONS**

```
[]
    Key for the temporary.

[--network]
    Delete the value of a network|site temporary.

[--all]
    Delete all temporaries.

```

**EXAMPLES**

```
# Delete temporary.
$ wp temporary delete sample_key
Success: Temporary deleted.

# Delete all temporaries.
$ wp temporary delete --all
Success: 14 temporaries deleted from the database.

```

#### wp temporary clean

[](#wp-temporary-clean)

Delete all expired temporaries.

```
wp temporary clean

```

**EXAMPLES**

```
$ wp temporary clean
Success: Expired temporaries deleted from the database.

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

2803d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/54c4bd393dafccafaf09bf6441bbd933db30b4d4fd153211f79636e8838cdac5?d=identicon)[dimadin](/maintainers/dimadin)

---

Top Contributors

[![dimadin](https://avatars.githubusercontent.com/u/2678421?v=4)](https://github.com/dimadin "dimadin (38 commits)")

---

Tags

cache

### Embed Badge

![Health badge](/badges/dimadin-wp-temporary/health.svg)

```
[![Health](https://phpackages.com/badges/dimadin-wp-temporary/health.svg)](https://phpackages.com/packages/dimadin-wp-temporary)
```

###  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)[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)[anahkiasen/flatten

A package for the Illuminate framework that flattens pages to plain HTML

33313.0k](/packages/anahkiasen-flatten)[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)
