Skip to content

Commit

Permalink
Merge pull request #273 from wp-graphql/fix/#265-improve-clarity-on-s…
Browse files Browse the repository at this point in the history
…ettings-page

fix: improve clarity on Cache settings page
  • Loading branch information
jasonbahl authored Feb 19, 2024
2 parents 10a9581 + 0799813 commit 7c7ca61
Showing 1 changed file with 56 additions and 8 deletions.
64 changes: 56 additions & 8 deletions src/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,22 @@ function () {
'graphql_cache_section',
[
'title' => __( 'Cache', 'wp-graphql-smart-cache' ),
'desc' => __( 'Caching and other settings related to improved performance of GraphQL queries.', 'wp-graphql-smart-cache' ),
]
);

register_graphql_settings_field(
'graphql_cache_section',
[
'name' => 'log_purge_events',
'label' => __( 'Log Purge Events', 'wp-graphql-smart-cache' ),
'desc' => __( 'Enabling this option will log purge events to the error log. This can be helpful when debugging what events are leading to specific purge events.', 'wp-graphql-smart-cache' ),
'type' => 'checkbox',
'default' => 'off',
'name' => 'network_cache_notice',
'type' => 'custom',
'callback' => static function ( array $args ) {
echo '
<h2>' . esc_html( __( 'Network Cache Settings', 'wp-graphql-smart-cache' ) ) . '</h2>
<p>' . esc_html( __( 'Below are settings that will modify behavior of the headers used by network cache clients such as varnish.', 'wp-graphql-smart-cache' ) ) . '</p>
<p>' . esc_html( __( 'Our recommendation is to use HTTP GET requests for queries and take advantage of the network cache (varnish, etc) and only enable and use Object Cache if GET requests are, for some reason, not an option.', 'wp-graphql-smart-cache' ) ) . '</p>
';
},
]
);

Expand All @@ -213,7 +217,7 @@ function () {
[
'name' => 'global_max_age',
'label' => __( 'Cache-Control max-age', 'wp-graphql-smart-cache' ),
'desc' => __( 'If set, a Cache-Control header with max-age directive will be set for all GraphQL responses. Value should be an integer, greater or equal to zero, or blank to disable. A value of 0 indicates that requests should not be cached (use with caution).', 'wp-graphql-smart-cache' ),
'desc' => __( 'Value, in seconds. (i.e. 600 = 10 minutes) If set, a Cache-Control header with max-age directive will be added to the responses GraphQL queries made by via non-authenticated HTTP GET request. Value should be an integer, greater or equal to zero. A value of 0 indicates that requests should not be cached (use with caution).', 'wp-graphql-smart-cache' ),
'type' => 'number',
'sanitize_callback' => function ( $value ) {
if ( ! is_numeric( $value ) ) {
Expand All @@ -229,6 +233,23 @@ function () {
]
);

register_graphql_settings_field(
'graphql_cache_section',
[
'name' => 'object_cache_notice',
'type' => 'custom',
'callback' => static function ( array $args ) {
echo '
<hr>
<h2>' . esc_html( __( 'Object Cache Settings', 'wp-graphql-smart-cache' ) ) . '</h2>
<p>' . esc_html( __( 'Below are settings that will impact object cache behavior.', 'wp-graphql-smart-cache' ) ) . '</p>
<p><strong>' . esc_html( __( 'NOTE', 'wp-graphql-smart-cache' ) ) . ':</strong> ' . esc_html( __( 'GraphQL Object Cache is only recommended if network cache cannot be used. When possible, we recommend using HTTP GET requests and network caching layers such as varnish.', 'wp-graphql-smart-cache' ) ) . '</p>
';
},
]
);

register_graphql_settings_field(
'graphql_cache_section',
[
Expand Down Expand Up @@ -257,12 +278,39 @@ function () {
]
);

register_graphql_settings_field(
'graphql_cache_section',
[
'name' => 'debugging_notice',
'type' => 'custom',
'callback' => static function ( array $args ) {
echo '
<hr>
<h2>' . esc_html( __( 'Debugging', 'wp-graphql-smart-cache' ) ) . '</h2>
<p>' . esc_html( __( 'Below are settings you can use to help debug', 'wp-graphql-smart-cache' ) ) . '</p>
';
},
]
);

register_graphql_settings_field(
'graphql_cache_section',
[
'name' => 'log_purge_events',
'label' => __( 'Log Purge Events', 'wp-graphql-smart-cache' ),
'desc' => __( 'Enabling this option will log purge events to the error log. This can be helpful when debugging what events are leading to specific purge events.', 'wp-graphql-smart-cache' ),
'type' => 'checkbox',
'default' => 'off',
]
);

register_graphql_settings_field(
'graphql_cache_section',
[
'name' => 'purge_all',
'label' => __( 'Purge Now!', 'wp-graphql-smart-cache' ),
'desc' => __( 'Purge GraphQL Cache. Select this box and click the save button to purge all responses stored in the GraphQL Cache.', 'wp-graphql-smart-cache' ),
'desc' => __( 'Purge GraphQL Cache. Select this box and click the save button to purge all responses stored in the GraphQL Cache. This should purge network caches and object caches (if enabled) for GraphQL Queries.', 'wp-graphql-smart-cache' ),
'type' => 'checkbox',
'default' => 'off',
'sanitize_callback' => function ( $value ) {
Expand Down

0 comments on commit 7c7ca61

Please sign in to comment.