Giter Site home page Giter Site logo

persistent-transients's Introduction

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 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.

persistent-transients's People

Contributors

philipnewcomer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.