Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize genlocks usage #19

Merged
merged 2 commits into from
Apr 1, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions advanced-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,14 @@ function add_debug_html_to_output( $debug_html ) {

// Recreate the permalink from the URL
$batcache->permalink = 'http://' . $batcache->keys['host'] . $batcache->keys['path'] . ( isset($batcache->keys['query']['p']) ? "?p=" . $batcache->keys['query']['p'] : '' );
$batcache->url_key = md5($batcache->permalink);
$batcache->generate_keys();
roborourke marked this conversation as resolved.
Show resolved Hide resolved
// Use the whole batcache key as the "url_key". The original version of Batcache would only track the genlock and version
// against the current URL path, rather than the whole batcache variant. This would mean that many requests to a single path
// (like a REST API endpoint) would all share a genlock.
$batcache->url_key = $batcache->key;
$batcache->configure_groups();
$batcache->url_version = (int) wp_cache_get("{$batcache->url_key}_version", $batcache->group);
$batcache->do_variants();
$batcache->generate_keys();

// Get the batcache
$batcache->cache = wp_cache_get($batcache->key, $batcache->group);
Expand Down Expand Up @@ -690,6 +693,11 @@ function add_debug_html_to_output( $debug_html ) {
die($batcache->cache['output']);
}

// If we were not able to get a genlock,
if ( $batcache->do && ! $batcache->genlock && $batcache->add_hit_status_header ) {
header( 'X-Batcache: BYPASS' );
header( 'X-Batcache-Reason: No Genlock' );
}
// Didn't meet the minimum condition?
if ( ! $batcache->do || ! $batcache->genlock )
return;
Expand Down