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 all commits
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
19 changes: 12 additions & 7 deletions advanced-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function ob($output) {
header( 'X-Batcache: BYPASS' );
header( 'X-Batcache-Reason: Canceled' );
}
wp_cache_delete( "{$this->url_key}_genlock", $this->group );
wp_cache_delete( "{$this->key}_genlock", $this->group );

return $output;
}
Expand All @@ -186,7 +186,7 @@ function ob($output) {
$this->configure_groups();

if ( $this->cancel !== false ) {
wp_cache_delete( "{$this->url_key}_genlock", $this->group );
wp_cache_delete( "{$this->key}_genlock", $this->group );
return $output;
}

Expand All @@ -204,7 +204,7 @@ function ob($output) {
header( 'X-Batcache-Reason: No content' );
}

wp_cache_delete( "{$this->url_key}_genlock", $this->group );
wp_cache_delete( "{$this->key}_genlock", $this->group );
return;
}

Expand All @@ -220,7 +220,7 @@ function ob($output) {
header( 'X-Batcache-Reason: Bad status code' );
}

wp_cache_delete( "{$this->url_key}_genlock", $this->group );
wp_cache_delete( "{$this->key}_genlock", $this->group );
return $output;
}

Expand Down Expand Up @@ -262,7 +262,7 @@ function ob($output) {
header( 'X-Batcache-Reason: Set-Cookie' );
}

wp_cache_delete( "{$this->url_key}_genlock", $this->group );
wp_cache_delete( "{$this->key}_genlock", $this->group );
return $output;
}

Expand All @@ -276,7 +276,7 @@ function ob($output) {
wp_cache_set($this->key, $this->cache, $this->group, $this->max_age + $this->seconds + 30);

// Unlock regeneration
wp_cache_delete("{$this->url_key}_genlock", $this->group);
wp_cache_delete("{$this->key}_genlock", $this->group);

if ( $this->cache_control ) {
// Don't clobber Last-Modified header if already set, e.g. by WP::send_headers()
Expand Down Expand Up @@ -586,7 +586,7 @@ function add_debug_html_to_output( $debug_html ) {

// Obtain cache generation lock
if ( $batcache->do ) {
$batcache->genlock = wp_cache_add("{$batcache->url_key}_genlock", 1, $batcache->group, 10);
$batcache->genlock = wp_cache_add("{$batcache->key}_genlock", 1, $batcache->group, 10);
}

if ( isset( $batcache->cache['time'] ) && // We have cache
Expand Down Expand Up @@ -690,6 +690,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