Cached WPDB Queries
Cached WordPress wpdb queries
Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/petenelson/cached-wpdb-queries/archive/refs/heads/trunk.zipCached WordPress wpdb queries
Specific queries in WordPress core are executed directly against the database (such as get_available_post_mime_types()) and currently
do not have filters that allow bypassing the SQL query that is executed. On large installations with tens of thousands of records in the wp_posts
table, some of these queries can run quite slow. This plugin allows for "caching" of the results of these queries via records in the options table
to improve performance.
Note: Use this sparingly and only to cache wpdb queries that currently cannot be cached or bypassed by other means.
How it works:
- Specific queries from core can be flagged for caching, such as:
SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = 'attachment' - Each original query is configured with:
originalThe original wpdb query from WordPress core.source_callbackthat is used to get the data to be cached.expiresin seconds for how long the results should be cached.create_records_callbackused to create records in the option table. This function is passed the results from the source callback.updatedThe new query that will be used instead against the options table.
See the code in get-available-post-mime-types.php function for an example. Basically it is taking the distint post_mime_type records for attachments,
creating records in the options table with specific prefixes, then running a wildcard starts-with query against the options table, rather than the wp_posts
table, to get the results.
Releases
2 releases.
These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.