-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdefault-cache-control.php
36 lines (29 loc) · 1.05 KB
/
default-cache-control.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
* Plugin Name: Be API - Cache-control
* Description: Add must-revalidate to the cache-control directive.
* Version: 1.0
* Author: BE API Technical team
* Author URI: https://www.beapi.fr
*/
namespace BEAPI\Plugin_Defaults\cache_control;
add_action( 'plugins_loaded', __NAMESPACE__ . '\\cache_control_default_settings' );
/**
* Add default setting for the cache control plugin
*/
function cache_control_default_settings() {
global $cache_control_options;
if ( empty( $cache_control_options ) ) {
return;
}
foreach ( $cache_control_options as $index => $options ) {
$options['s_maxage'] = $options['max_age'];
$options['max_age'] = 0;
// On Server error, the page can be served 3 times the original value
$options['staleerror'] = $options['s_maxage'] * 3;
// The stored by Varnish will be served for 5 times the original value even if the page is expired.
// Server will get the new version as soon as one new user get it.
$options['stalereval'] = $options['s_maxage'] * 5;
$cache_control_options[ $index ] = $options;
}
}