wp-graphql-cache icon indicating copy to clipboard operation
wp-graphql-cache copied to clipboard

Update field cache to allow it to be used wihtout the query_name

Open zacscott opened this issue 4 years ago • 1 comments

Update field caching to work across multiple queries.

This PR allows a field cache to be configured across multiple / all queries. When the query_name parameter is omitted, a field cache will be global and not tied to a specific query at all.

This is useful for caching fields which are included across multiple queries. An example from a project I am working on is the menus, which are included in every query we do. I can configure a field cache like so and have it computed on once globally for all of our queries.

E.g.

CacheManager::register_graphql_field_cache(
	array(
		'zone'       => 'menus',
		'field_name' => 'headerMenus',
		'expire'     => 600, // seconds.
	)
);

This is still compatible with fields configured with a query_name and will function exactly as it does currently.

zacscott avatar Jan 25 '21 03:01 zacscott

Doesn't 'query_name' => '*' already enable this?

esamattis avatar Dec 22 '21 11:12 esamattis