[wp-trac] [WordPress Trac] #61343: Improve caching in get_calendar function
WordPress Trac
noreply at wordpress.org
Fri Apr 10 10:33:52 UTC 2026
#61343: Improve caching in get_calendar function
-------------------------------------------------+-------------------------
Reporter: spacedmonkey | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting
| Review
Component: Widgets | Version:
Severity: normal | Resolution:
Keywords: good-first-bug has-patch reporter- | Focuses:
feedback has-unit-tests | performance
-------------------------------------------------+-------------------------
Comment (by MythThrazz):
New PR in #11547 with a different approach than PR #6708:
**Cache architecture:** Replaced the monolithic cache array (all
variations in one key) with individual cache keys per variation
(`get_calendar_{hash}`). Reads no longer deserialize all months/post-
types, and writes only touch one entry.
**Cache invalidation:** Switched from `save_post`/`delete_post` to
`clean_post_cache` as suggested. Uses `wp_cache_flush_group('calendar')`
with a generation counter fallback for persistent cache implementations
that don't support group flushing.
**Raw SQL kept:** The suggestion to replace `$wpdb` queries with
`WP_Query` was evaluated but not implemented — `SELECT DISTINCT
DAYOFMONTH(post_date)` returns max 31 rows, while `WP_Query` with
`posts_per_page=-1` (as in PR #6708) would load all posts in the month.
The raw queries are more efficient here.
**Date math:** Replaced the MySQL `DATE_FORMAT(DATE_ADD(...))` query with
PHP `gmdate()` to eliminate a DB roundtrip for pure date calculation.
Includes unit tests for cache invalidation, individual keys, and
flush_group behavior. All existing tests pass.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61343#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list