arraypress/wp-storage-utils

The three storage operations WordPress lacks: cache-or-compute, delete-by-prefix, and reading a stored value as the type it is meant to be.

Maintainers

Package info

github.com/arraypress/wp-storage-utils

Homepage

pkg:composer/arraypress/wp-storage-utils

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-08-25 19:47 UTC

This package is auto-updated.

Last update: 2026-08-26 09:49:27 UTC


README

The three storage jobs WordPress leaves you to write: cache-or-compute, delete by prefix, and reading a stored value back as the type you wanted.

What it does

get_transient() returns false both when nothing is cached and when the cached value is false, so the cache-or-compute pattern gets written by hand, subtly wrong, in every plugin. remember() wraps the stored value so the two are distinguishable.

Deleting your own transients when a plugin uninstalls has no API at all, so everyone writes a DELETE ... LIKE — usually forgetting that the timeout rows do not carry the prefix, and leaving half of them behind forever.

And anything out of the options table is a string, so it needs casting before it is useful.

Features

  • Cache-or-compute that can store false, null or 0 without confusion
  • Delete every option, transient or meta row sharing a prefix, on uninstall
  • Remove both halves of a transient, so nothing is orphaned in wp_options
  • Cast a stored value to bool, int, float, array or a list of ids
  • Escapes LIKE wildcards, so an underscore in your prefix stays literal

Installation

composer require arraypress/wp-storage-utils

Quick start

use ArrayPress\StorageUtils\Cache;
use ArrayPress\StorageUtils\Cast;
use ArrayPress\StorageUtils\Cleanup;

// Computed once an hour, and it can legitimately return false.
$is_eligible = Cache::remember( 'sc_eligible_' . $user_id, function () use ( $user_id ) {
    return expensive_eligibility_check( $user_id );
} );

// Options come back as strings.
$limit = Cast::int( get_option( 'sc_download_limit' ), 5 );

// On uninstall, take everything with you.
Cleanup::options( 'sugarcart_' );
Cleanup::transients( 'sugarcart_' );
Cleanup::meta( 'sugarcart_', 'post' );

Requirements

  • PHP 8.3 or later
  • WordPress 7.1 or later

License

GPL-2.0-or-later