Skip to content

Avoid redundant cache misses  #482

@joemcgill

Description

@joemcgill

Generally, when get_option() is called and the option does not exist, WordPress will store the option in the 'notoptions' cache to avoid unnecessary DB requests on subsequent calls to the option. In https://core.trac.wordpress.org/changeset/56595 (shipped in WP 6.4), a change was made to check object cache (when present) before checking the 'notoptions' cache to avoid an unnecessary check of 'notoptions' when the option does exist, but this has been reported to cause an increase in requests to object caches when the option does not exist in https://core.trac.wordpress.org/ticket/62692 if the object cache implementation does not ensure that cache misses avoid redundant calls to the same non-existent option.

This comment, on the second ticket includes a list of implementations affected, including this one.

Even when this is fixed and shipped (hopefully in WP 6.8) people running versions of WP from 6.4–6.7 will still be affected by this bug unless it's handled at the object cache layer.

Reproduction steps

Call get_option( 'notexist' ) in a loop. Prior to 6.4, this would generate 2 total cache gets; after 6.4, it generates an infinite number, as each iteration of the cycle triggers a cache get which misses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions