Skip to content

Commit 26e9b2f

Browse files
authored
Merge pull request #107 from bluehost/file-based-and-extend-expirations
File based and extend expirations
2 parents b794dd1 + 1b616e4 commit 26e9b2f

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
"scripts": {
4141
"lint": [
4242
"vendor/bin/phpcs endurance-page-cache.php --standard=Bluehost"
43+
],
44+
"fix": [
45+
"vendor/bin/phpcbf endurance-page-cache.php --standard=Bluehost"
4346
]
4447
}
4548
}

endurance-page-cache.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ class Endurance_Page_Cache {
7171
*/
7272
public $cloudflare_tier = 'basic';
7373

74+
/**
75+
* File Based enabled
76+
*
77+
* @var bool
78+
*/
79+
public $file_based_enabled = false;
80+
7481
/**
7582
* Whether or not to force a purge.
7683
*
@@ -166,6 +173,7 @@ public function __construct() {
166173
$this->cloudflare_enabled = (bool) $cloudflare_state;
167174
$this->cloudflare_tier = ( is_numeric( $cloudflare_state ) && $cloudflare_state ) ? 'basic' : $cloudflare_state;
168175
$this->udev_api_services['cf'] = $this->cloudflare_tier;
176+
$this->file_based_enabled = (bool) get_option( 'endurance_file_enabled', false === strpos( dirname( __FILE__ ), 'public_html' ) );
169177

170178
array_push( $this->cache_exempt, rest_get_url_prefix() );
171179

@@ -359,7 +367,7 @@ public function to_snake_case( $value, $delimiter = '_' ) {
359367
* @return bool True if uses file system to cache
360368
*/
361369
public function use_file_cache() {
362-
return false === strpos( dirname( __FILE__ ), 'public_html' );
370+
return $this->file_based_enabled;
363371
}
364372

365373
/**
@@ -1046,7 +1054,11 @@ public function htaccess_contents_rewrites( $rules ) {
10461054
$base = wp_parse_url( trailingslashit( get_option( 'home' ) ), PHP_URL_PATH );
10471055
$cache_url = $base . str_replace( get_option( 'home' ), '', WP_CONTENT_URL . '/endurance-page-cache' );
10481056
$cache_url = str_replace( '//', '/', $cache_url );
1049-
$additions = "<ifModule mod_headers.c>\n" . 'Header set X-Endurance-Cache-Level "' . $this->cache_level . '"' . "\n</ifModule>\n";
1057+
$additions = "\n
1058+
<ifModule mod_headers.c>\n" . '
1059+
Header set X-Endurance-Cache-Level "' . $this->cache_level . '"' . "\n" . '
1060+
Header set X-nginx-cache "WordPress"' . "\n
1061+
</ifModule>\n";
10501062

10511063
if ( $this->use_file_cache() ) {
10521064
$additions .= 'Options -Indexes ' . "\n" . '
@@ -1081,7 +1093,7 @@ public function htaccess_contents_expirations( $rules ) {
10811093
'text/css' => '1 month',
10821094
'application/pdf' => '1 month',
10831095
'text/javascript' => '1 month',
1084-
'text/html' => '5 minutes',
1096+
'text/html' => '2 hours',
10851097
);
10861098

10871099
$file_types = wp_parse_args( get_option( 'epc_filetype_expirations', array() ), $default_files );
@@ -1288,7 +1300,7 @@ public function update_level_expirations( $level ) {
12881300
'text/css' => '1 week',
12891301
'application/pdf' => '1 week',
12901302
'text/javascript' => '1 month',
1291-
'text/html' => '4 hours',
1303+
'text/html' => '8 hours',
12921304
'default' => '1 week',
12931305
);
12941306
break;
@@ -1302,7 +1314,7 @@ public function update_level_expirations( $level ) {
13021314
'text/css' => '24 hours',
13031315
'application/pdf' => '1 week',
13041316
'text/javascript' => '24 hours',
1305-
'text/html' => '5 minutes',
1317+
'text/html' => '2 hours',
13061318
'default' => '24 hours',
13071319
);
13081320
break;

0 commit comments

Comments
 (0)