Skip to content

Can we exclude specific queries from being cached?  #177

@alexkey89

Description

@alexkey89

e.g When I activated smart cache, customer query was getting cached. I want to be able to exclude specific queries so that they are never cached simply by sending a variable in the request or having the specified queries in settings page. i created this snippet as a hack. If a more advanced php person can solve this in better way with new release, that would be great.

So every time I request it will toggle the cache. However this isn't ideal.

add_action( 'init', function() {
    if (
        $_SERVER['REQUEST_METHOD'] === 'POST' &&
        isset( $_REQUEST['disable_cache'] )
    ) {
        if ( is_plugin_active( 'wp-graphql-smart-cache/wp-graphql-smart-cache.php' ) ) {
            add_filter( 'graphql_get_setting_section_field_value', function( $value, $default, $option_name, $section_fields, $section_name ) {
                if ( $option_name === 'cache_toggle' ) {
                    return false;
                }
                return $value;
            }, 10, 5 );
        }
    }
} );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions