valu-digital / wp-graphql-cache

Flexible caching framework for WPGraphQL
GNU General Public License v2.0
41 stars 9 forks source link

Caching queries with variables #10

Open hatsumatsu opened 3 years ago

hatsumatsu commented 3 years ago

Thanks for this plugin!

I was wondering how caching a named query with query variables works. Let's say I have a paginated query using the after filter.

query MyPosts( $after: String ) {
  posts(after: $after, first: 10) {
    edges {
      node {
        title
      }
    }
  }
}

Would caching query MyPosts (see below) automatically handle different versions of the query based on the passed variables? Or does it ignore variables all together?

use WPGraphQL\Extensions\Cache\CacheManager;

CacheManager::register_graphql_query_cache([
    'query_name' => 'MyPosts',
    'expire' => 120,
]);
blocka commented 3 years ago

seems like would ignore them? I think this would be a very useful feature