Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/philipnewcomer/persistent-transients
Persistent transients for WordPress
https://github.com/philipnewcomer/persistent-transients
caching transients wordpress wordpress-development wordpress-php-library wordpress-transients
Last synced: 11 days ago
JSON representation
Persistent transients for WordPress
- Host: GitHub
- URL: https://github.com/philipnewcomer/persistent-transients
- Owner: philipnewcomer
- License: gpl-2.0
- Created: 2017-01-24T22:00:19.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-16T11:42:55.000Z (over 6 years ago)
- Last Synced: 2024-05-01T13:51:42.858Z (6 months ago)
- Topics: caching, transients, wordpress, wordpress-development, wordpress-php-library, wordpress-transients
- Language: PHP
- Size: 10.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Persistent Transients for WordPress
This library exists to fill a very specific use case: when you need transients that are guaranteed to exist until their expiration timestamp.
In most cases, you should be using normal [transients](https://codex.wordpress.org/Transients_API) instead. Don't use this library unless you have a good reason to.
## Background
WordPress transients are not guaranteed to persist until their expiration timestamp. There are a number of things, including core updates, or a full in-memory object cache, that can cause a transient to be deleted before it is due to expire.
However, sometimes you may need to store data that is transient, cannot be regenerated as you would typically do with a normal transient, and must be available up to the time when it is due to expire. An example of this use case is an email confirmation link, with a unique key generated by `uniqid()`. This data cannot be regenerated, and must be guaranteed to persist in the database until its expiration timestamp.
Using a custom post type or custom database table may be overkill for this type of thing, and that's where this library comes into play.
## What This Does
Persistent Transients stores transient data in the WordPress options table. Expired transients are garbage collected once per day. Because it does not use the regular WordPress transients system, and is not stored in the in-memory object cache, these transients are not affected by any of the things that may cause a normal transient to expire prematurely.
## Usage
Persistent Transients provides three drop-replacements for the regular WordPress transient functions: `set`, `get`, and `delete`.
```
PersistentTransients\set( $transient, $value, $expiration );
```* **$transient** (string) A unique identifier for the cached data.
* **$value** (array|object) The data to save.
* **$expiration** (integer) The number of seconds to keep the data.*Saves a persistent transient. Will overwrite an existing transient with the same name if it exists.*
```
PersistentTransients\get( $transient );
```* **$transient** (string) A unique identifier for the cached data.
*Returns the transient value, or `false` if it has expired or does not exist.*
```
PersistentTransients\delete( $transient );
```* **$transient** (string) A unique identifier for the cached data.
*Deletes a transient. Use if you want to remove a transient before its expiration.*
## Installation
This is a Composer package, not a traditional WordPress plugin. Install [via Composer](https://packagist.org/packages/philipnewcomer/persistent-transients).