Skip to content

Conversation

@jasonbahl
Copy link
Collaborator

This PR adds a new graphql_cache_is_object_cache_inabled filter that can allow 3rd party developers to dynamically enable/disable the object cache.

For example, (as mentioned in #177) a query param in the request, such as ?disable_cache could be read by this filter and disable the cache for that request.

This filter could be used like so:

add_filter( 'graphql_cache_is_object_cache_enabled', function( $enabled, $request ) {
  
  // disable caching when `?disable_cache` is included as a query param
  if (
        $_SERVER['REQUEST_METHOD'] === 'POST' &&
        isset( $_REQUEST['disable_cache'] )
    ) {
      return false;
    }

  return $enabled;
}, 10, 2 );

…ally enabling/disabling the object cache.

- composer run fix-cs
@jasonbahl jasonbahl added the type: enhancement Improvements to existing functionality label Nov 11, 2022
@jasonbahl jasonbahl self-assigned this Nov 11, 2022
@jasonbahl jasonbahl merged commit b66def5 into main Nov 11, 2022
@jasonbahl jasonbahl mentioned this pull request Nov 11, 2022
@jasonbahl jasonbahl changed the title feat: add new "graphql_cache_is_object_cache_inabled" filter feat: add new "graphql_cache_is_object_cache_enabled" filter Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement Improvements to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants