Skip to content

Commit

Permalink
Merge pull request #19 from humanmade/optimize-genlock
Browse files Browse the repository at this point in the history
Optimize genlocks usage
  • Loading branch information
joehoyle authored Apr 1, 2021
2 parents 86743fa + 5e8fbb7 commit 3a7f724
Showing 1 changed file with 12 additions and 7 deletions.
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

0 comments on commit 3a7f724

Please sign in to comment.