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]
- Caching: APC vs APCu vs OPcache
- Prevent WordPress from sending Cache-control http header
- Optimize apache for WP use
- Is there any danger in deleting all transients?
- Best practices for using the transients API
- Does a query executed through wpdb class get cached?
- Using transients in conjunction with memcached
- 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
- Storing posts social counters by using transient api
- 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)
- How to force content refresh of a page that has been loaded previously by the user? [closed]
- Help Pinpointing Source of Caching Issue
- Can someone explain WordPress caching, and what’s the best in my scenario?
- wp_transients | wp_object_cache VS SESSIONS & Cookies?
- APC object caching in combination Batcache/memcached page caching?
- WordPress caching in development
- What is difference between ‘Page Cache’ and ‘Object Cache’ in WordPress?
- W3 total Cache – Site with query strings
- Get the timout value of a saved transient?
- Programmatically insert hierarchical terms & set terms for post causes glitch? [duplicate]
- Getting soft 404 errors (200 status) when caching plugins are enabled
- How to totally disable cache in WordPress?
- W3 Total Cache plugin integration
- Transient API and caching Plugins
- How to cache posts based on $_GET? Option name is too long? Options / transients
- Execute a piece of code also when the cached version of a page is served
- Method to make definitively static an abandoned WP blog
- pass-protected pages and posts not protected after enter them 1 time
- Static HTML page caching for large website [closed]
- WordPress caching issue
- WP Super Cache Bug with Ubermenu
- Problem with caching, W3TC [closed]
- How to find time last viewed?
- WP Rocket Cache Lifespan – Never clear cache? [closed]
- Disable feed cache for custom RSS feed?
- How do I enable dynamic content in a theme cached with WP Super Cache?
- How to cache a different page version based on HTTP header?
- Live website is not showing the changes I’ve made [closed]
- WebHostingBuzz cache statement
- W3 Total Cache can’t create files [closed]
- Files cached as CSS or PHP?
- How to cache wp_query with pagination using transients?
- A bunch of unrelated wordpress using same memcached don’t store correctly their datas
- RSS: fetch_feed caching with different caching delay per feed?
- How to be sure to get last page version without ANY cache?
- Is there a limit to size of data stored in update_option()?
- Last-Modified header support doesnât speed up server processing – want more
- Browser cache for dynamic content (list of tags)
- How to specify expiration of cacheable resources? [closed]
- APC fragmention woes on Apache AWS EC2 Small instance with WordPress and W3TC [closed]
- w3 total cache – Object Caching 2165/2469 objects? [closed]
- Website working fine when logged in but not working fine when we logged out
- Changing WP Object Caching during runtime
- Best practices for the cache of a static WordPress site, including CDN Cache and Cache Plugin
- Site’s first loading on a new browser with no cache is messed up
- Save large WP_Query to transient === false
- Woocommerce – how to round up all prices to end in .99
- Site speed slows when user logged in
- WordPress mobile version is not responsive anymore after installing varnish
- Admin area is caching posts in the editor
- Having issues fixing site speed
- Is there a way to cache WordPress that does not loads core?
- Need to refresh page after each change
- leverage browser caching in wordpress
- WordPress varnish pages printed twice
- Feed cache fallback – A feed could not be found
- WordPress Userroles button getting cached
- How to let users clear their posts cache with WP Super Cache?
- Having 4000 posts, my site is so slow
- Super cache caches mobile pages for desktop
- Debug Performance Issues
- cache reset button and question about deleting cache
- Cleared wp-cache and file is still not updated [closed]
- Bluehost WebHost and performance problems with W3TC [closed]
- get_theme_mod returning cached values regardless of apache restart
- Caching with dynamic content
- Levels of caching and impact on the WordPress web site
- CSS changes not taking effect [closed]
- what is the cache directory for in my theme? (version control it?)
- Multiple WordPress sites eat up a lot of RAM
- What is the best way to cache pages and queries in WordPress?
- Cannot add version of main.css to wordpress on testing enviroment
- Cache a number of responses from external json feeds?
- How can i store cache of wordpress a database request without plugins?
- How can I wordpress cache a database request with no existing plugin?