@PublicApi public class CacheControl extends java.lang.Object
To best use this class you need to pass a CacheControl object to each DataFetcher
and have them decide on
the caching hint values.
The easiest way to do this is create a CacheControl object at query start and pass it in as a "context" object via ExecutionInput.getGraphQLContext()
and then have
each DataFetcher
that wants to make cache control hints use that.
Then at the end of the query you would call addTo(graphql.ExecutionResult)
to record the cache control hints into the ExecutionResult
extensions map as per the specification.
Modifier and Type | Class and Description |
---|---|
static class |
CacheControl.Scope
If the scope is set to PRIVATE, this indicates anything under this path should only be cached per-user,
unless the value is overridden on a sub path.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CACHE_CONTROL_EXTENSION_KEY |
Modifier and Type | Method and Description |
---|---|
ExecutionResult |
addTo(ExecutionResult executionResult)
This will record the values in the cache control object into the provided execution result object which creates a new
ExecutionResult
object back out |
CacheControl |
hint(DataFetchingEnvironment dataFetchingEnvironment,
CacheControl.Scope scope)
This creates a cache control hint for the specified field being fetched with a specified scope
|
CacheControl |
hint(DataFetchingEnvironment dataFetchingEnvironment,
java.lang.Integer maxAge)
This creates a cache control hint for the specified field being fetched with a PUBLIC scope
|
CacheControl |
hint(DataFetchingEnvironment dataFetchingEnvironment,
java.lang.Integer maxAge,
CacheControl.Scope scope)
This creates a cache control hint for the specified field being fetched
|
CacheControl |
hint(ResultPath path,
CacheControl.Scope scope)
This creates a cache control hint for the specified path
|
CacheControl |
hint(ResultPath path,
java.lang.Integer maxAge)
This creates a cache control hint for the specified path
|
CacheControl |
hint(ResultPath path,
java.lang.Integer maxAge,
CacheControl.Scope scope)
This creates a cache control hint for the specified path
|
static CacheControl |
newCacheControl()
Creates a new CacheControl object that can be used to trick caching hints
|
public static final java.lang.String CACHE_CONTROL_EXTENSION_KEY
public CacheControl hint(ResultPath path, java.lang.Integer maxAge, CacheControl.Scope scope)
path
- the path to the field that has the cache control hintmaxAge
- the caching time in secondsscope
- the scope of the cache control hintpublic CacheControl hint(ResultPath path, CacheControl.Scope scope)
path
- the path to the field that has the cache control hintscope
- the scope of the cache control hintpublic CacheControl hint(ResultPath path, java.lang.Integer maxAge)
path
- the path to the field that has the cache control hintmaxAge
- the caching time in secondspublic CacheControl hint(DataFetchingEnvironment dataFetchingEnvironment, java.lang.Integer maxAge, CacheControl.Scope scope)
dataFetchingEnvironment
- the path to the field that has the cache control hintmaxAge
- the caching time in secondsscope
- the scope of the cache control hintpublic CacheControl hint(DataFetchingEnvironment dataFetchingEnvironment, java.lang.Integer maxAge)
dataFetchingEnvironment
- the path to the field that has the cache control hintmaxAge
- the caching time in secondspublic CacheControl hint(DataFetchingEnvironment dataFetchingEnvironment, CacheControl.Scope scope)
dataFetchingEnvironment
- the path to the field that has the cache control hintscope
- the scope of the cache control hintpublic static CacheControl newCacheControl()
public ExecutionResult addTo(ExecutionResult executionResult)
ExecutionResult
object back outexecutionResult
- the starting execution result object