Performance tweaks for WordPress to cache HTTP API Call response.
Performance tweaks for WordPress to cache WordPress API Call responses made by other plugins. This will reduce HTTP requests to external hosts if the plugin does not implement caching on their API calls.
- Download the plugin
zip fileand save it ascache-http-response.zip. - Upload and install the plugin zip file
cache-http-response.zipthrough the WordPress plugins screen directly. - Activate the plugin through the ‘Plugins’ screen in WordPress.
WP-CLI is the official command-line interface for WordPress. You can install cache-http-response using the wp command like this:
wp plugin install --activate https://github.com/nawawi/cache-http-response/archive/main.zip
wp plugin install --activate https://github.com/nawawi/cache-http-response/archive/main.zip --force
Cache HTTP Response supports the GitHub Updater plugin WordPress. The plugin enables automatic updates from this GitHub Repository. You will find all information about the how and why at the plugin wiki page.
This plugin behaviour can be changed using a filter hook. You may load it as a 'mu-plugins' script. Copy this code and place it in wp-content/mu-plugins/cache-http-response-hook.php.
<?php
add_filter(
'cache_http_reponse/ttl',
function() {
// 1 hour.
return 3600;
}
);
add_filter(
'cache_http_reponse/include',
function($urls) {
//$urls[] = '';
return $urls;
}
);
add_filter(
'cache_http_reponse/exclude',
function($urls) {
//$urls[] = '';
return $urls;
}
);By default, it will cache all URL if no URL apply to this filter.
add_filter(
'cache_http_reponse/include',
function($urls) {
$urls[] = 'https://apihostname1.name/api';
$urls[] = 'https://apihostname2.name/api';
return $urls;
}
);
Exclude URL from the cache.
add_filter(
'cache_http_reponse/exclude',
function($urls) {
$urls[] = 'https://apihostname1.name/api';
$urls[] = 'https://apihostname2.name/api';
return $urls;
}
);
Cache lifespan in seconds. By default, it is set to 300 seconds.
add_filter(
'cache_http_reponse/ttl',
function() {
return 300;
}
);
Exclude *.wordpress.org URL. By default it is set to true.
add_filter(
'cache_http_reponse/exclude_wporg',
'__return_true'
);
Exclude Site URL. By default it is set to true.
add_filter(
'cache_http_reponse/exclude_localhost',
'__return_true'
);
1.0.0
- Initial release.