Make WordPress Core

Opened 3 weeks ago

Last modified 2 weeks ago

#61296 new enhancement

Add "force" parameter to get_option and get_transient

Reported by: juvodesign's profile juvodesign Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords: has-patch
Focuses: Cc:

Description

Since both get_transient and get_option already have built in ways to handle object caching, i think it would be reasonable to add the force parameter and pass it through to wp_cache_get.

I imagine having the default parameter set to false. This shouldn't break anything but give developers better control in cases where the cache is being updated while in a request lifecycle.

I stumbled across this when using persistent object caching:
https://github.com/rhubarbgroup/redis-cache/issues/523

Other users are also missing this option:
https://wordpress.stackexchange.com/questions/100040/can-i-force-get-option-to-go-back-to-the-db-instead-of-cache

If this is something worth considering, I would happily provide a patch.

Change History (1)

This ticket was mentioned in PR #6691 on WordPress/wordpress-develop by @snehapatil02.


2 weeks ago
#1

  • Keywords has-patch added

### Ticket: https://core.trac.wordpress.org/ticket/61296

## Description

This PR enhances the get_transient and get_option functions in WordPress by introducing a new optional $force parameter. The $force parameter allows developers to bypass the object cache and retrieve the latest transient value directly from the database.

### Changes Made

  1. Function Signature: Added the $force parameter to the function signature with a default value of false.
  2. Cache Logic: Modified the function logic to check if the $force parameter is set to true. If true, the function bypasses the cache and retrieves the transient value directly from the database.

### Why This Change is Necessary

  • Currently, developers have limited control over transient retrieval, especially in scenarios where the cache is updated during a request lifecycle.
  • This enhancement provides flexibility and control by allowing developers to force a database query for the latest transient value when needed.
Note: See TracTickets for help on using tickets.