I eventually used a combination of update_option
and WP Cron:
// Create the option.
update_option('foo', 'bar', false);
/**
* Schedule it to be deleted one week from now.
*
* @param int Expiration timestamp
* @param string Hook that will be invoked
* @param string Params to send to the hook callback
*/
wp_schedule_single_event( time() + WEEK_IN_SECONDS, 'expire_option', [ 'foo' ] );
// Register the hook.
add_action( 'expire_option', 'expire_option_callback', 10, 1 );
// This will be called by WP Cron when we want to "expire" the option, one week after its creation.
function expire_option_callback( $option_name ) {
delete_option( $option_name );
}
The only drawback is that the option won’t be expired if WP Cron is not working in the site. If this is unnaceptable, you’ll need a more robust solution mimicking how transients are saved and expired in the DB.
Related Posts:
- Should I use Transient API to store HTML String, or Object?
- Using a wildcard with delete_transient()
- Fragment caching increasing database queries
- How to purge all transient caches?
- Transient / object cache maximum key length [duplicate]
- How to purge all transient caches?
- Transients are not expiring as expected in simple custom plugin
- How to store or cache custom shopping cart data for every user’s session
- How to decode wordpress transient cache stored in database?
- Hook an action when a transient is deleted ? Can’t get it to work!
- After having installed APC Object Cache Backend transients stopped working
- Should I use transients for these API call results?
- W3 total cache – cache refresh programmatically [closed]
- How does object caching work?
- Caching: APC vs APCu vs OPcache
- Best way to show Dynamic Content on a Cached WordPress Site?
- Is define(‘WP_CACHE’, true) needed for object caching?
- Prevent WordPress from sending Cache-control http header
- Optimize apache for WP use
- Is get_option() faster than accessing get_transient()?
- Cache remote (HTTP) request with Transients API
- Is there any danger in deleting all transients?
- Pros and Cons for high “expire time” on wp-super-cache or w3-total-cache? [closed]
- Limit cache size from W3 Total Cache [closed]
- Best practices for using the transients API
- Does a query executed through wpdb class get cached?
- Using transients in conjunction with memcached
- Configuring WordPress for Amazon CloudFront Caching?
- Caching: Force fresh content for logged-in users (potentially by adding a query variable to the URL)
- Multiple WordPress sites eat up alot of RAM
- What exactly is an advanced object cache?
- Storing posts social counters by using transient api
- Will I see a performance hit if I use native API calls like get_the_title() instead of $post->post_title?
- WordPress Browser Cache with W3-Total-Cache doesn’t show new posts [closed]
- Nginx + WordPress + HHVM: Why isn’t Batcache working? Would Varnish help even more?
- Does a low traffic WordPress site need a caching plugin and a CDN
- Automatically Refresh WordPress Stylesheet
- wp_cache_set() or wp_cache_add()
- How to use cache with simplepie
- Can I force get_option to go back to the DB instead of cache?
- WordPress transients for a shortcode
- Which WordPress pages/URLs should never be cached?
- How to archive a wordpress site (make it read only)
- Stale cache handling with a persistent object cache
- Is priming a Transient Cache possible?
- Varnish + W3 Total Page Cache [closed]
- Are there any server requirements for WordPress transients to work properly?
- Should the caching of WordPress menus be specific to each page?
- Writing a cache manifest file for a WordPress blog (app cache, offline web applications)
- Transients vs CRON +Custom Fields: Caching Data Per Post
- Transient not working for custom loops
- W3 Total Cache doesn’t detect memcached [closed]
- Settings to get the most out of W3 Total Cache
- How to force content refresh of a page that has been loaded previously by the user? [closed]
- Help Pinpointing Source of Caching Issue
- How to clear cache without a plugin [closed]
- can’t see live version of style.css – is it web server caching?
- Want to enforce the visitor to load the new version of your stylesheets and scripts [closed]
- Can someone explain WordPress caching, and what’s the best in my scenario?
- Speed up WordPress
- wp-super-cache exclude file from caching
- wp_transients | wp_object_cache VS SESSIONS & Cookies?
- APC object caching in combination Batcache/memcached page caching?
- Transients API and multisite
- Should the page cache be refreshed often? [closed]
- WordPress caching in development
- Plugin a specific cache functionality?
- What is difference between ‘Page Cache’ and ‘Object Cache’ in WordPress?
- W3 total Cache – Site with query strings
- Possible to configure nginx to ignore cache for logged in users in certain roles only?
- Check if a user is connected and get is ID without fully loading wordpress
- Transient caching for wp query
- Should I enable FastCGI on WordPress?
- Get the timout value of a saved transient?
- Programmatically insert hierarchical terms & set terms for post causes glitch? [duplicate]
- Will caching WordPress affect session variables, custom filed updates and displaying images from a non wordpress table?
- Getting soft 404 errors (200 status) when caching plugins are enabled
- How to totally disable cache in WordPress?
- Automatically enabled caching in some hosting companies w/o visible plugin (Must use plugin)
- Database Cache and Object Cache Difference?
- Register script version not showing
- W3 Total Cache plugin integration
- Transient API and caching Plugins
- How to cache posts based on $_GET? Option name is too long? Options / transients
- WordPress Caching – Transients API or “update_user_meta ” Cronjob?
- When use a cache system with WordPress
- server load. $_SERVER[‘REMOTE_ADDR’] and $_SERVER[‘HTTP_HOST’] [closed]
- Optimizing Jetpack for WordPress [closed]
- Is it possible to save an entire piece of rendered HTML in a transient?
- Execute a piece of code also when the cached version of a page is served
- Clearing cached plugin data if it is using an external object cache
- Method to make definitively static an abandoned WP blog
- How do I fetch feed info from cache instead of directly from feed?
- pass-protected pages and posts not protected after enter them 1 time
- Can a WordPress blog be entirely hosted on a CDN if cached?
- Static HTML page caching for large website [closed]
- Transient feeds and caching error
- Transient loop issue
- To have WordPress interact with memcached it must be installed as a PHP extension?
- WordPress caching issue