Make WordPress Core

Opened 9 months ago

Closed 9 months ago

#59593 closed enhancement (duplicate)

Improve query class cache key generation for array values

Reported by: spacedmonkey's profile spacedmonkey Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Cache API Keywords:
Focuses: performance Cc:

Description

n the current WordPress core, cache keys are generated for all query classes by serializing the array of query arguments to create a unique cache key. This mechanism works effectively for most cases, but it falls short when query classes support array values as arguments. An example of this is the postin parameter in the WP_Query class.

The issue arises when different orders of array values are used for the postin argument while making essentially identical queries. In such cases, distinct cache keys are generated for queries that should ideally produce the same result.

For instance, consider the following two queries:

Example.

get_posts(['post__in' => [123, 456] ]);
get_posts(['post__in' => [456, 123] ]);

Both queries are conceptually identical and should return the same results. However, the current cache key generation system treats them as separate queries, leading to potential inefficiencies and unnecessary cache duplication.

A more specific case where this issue can impact performance is the combination of the orderby parameter with the postin parameter in a WP_Query. Depending on the order of array values, the cache query value may differ, even though the actual result remains the same.

To address this issue, we propose enhancing the cache key generation process for query classes that support array values as arguments. This improvement will help ensure that functionally identical queries generate the same cache key, ultimately improving performance and cache efficiency.

By addressing this limitation in cache key generation, WordPress can better optimize its caching mechanisms and provide a more efficient experience for developers and users.

Change History (1)

#1 @spacedmonkey
9 months ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #59516.

Note: See TracTickets for help on using tickets.