Update Cache Rules
By default the cache rules for the caching is Skylark are very simple. Every query (apart from a few configuration queries) have a blanket 60 second cache enabled.
The setCacheConfig
mutation can be used to update the cache rules for specific types or even fields within that type.
The following options are available for setting cache rules:
types
: The types to applied the rules tomax_age
: The amount of time (in seconds) responses stay cached forstale_while_revalidate
: The amount of time (in seconds) stale query results that match the types should be served while fresh data is already being fetched in the background
Updating Cache For All Queries
This example shows updating the default cache on all queries from 60 seconds to 86400 seconds (24 hours).
Note that multiple rules can be applied at once and multiple types per rule.
mutation setCacheConfig {
setCacheConfig(rules: [
{
types: [
"Query"
]
max_age: 86400
}
]) {
rules {
types
max_age
}
}
}
Updating Cache Rules for Specific Queries
This example shows setting a rule for all queries apart from some getting or listing images which have a shorter 1 hour cache and getting or listing Assets which are not cached at all.
mutation setCacheConfig {
setCacheConfig(rules: [
{
types: [
"Query"
]
max_age: 86400
},
{
types: [
"Query.getSkylarkImage",
"Query.listSkylarkImage",
],
max_age: 3600
},
{
types: [
"Query.getSkylarkAsset",
"Query.listSkylarkAsset"
],
max_age: 0
},
]) {
rules {
types
stale_while_revalidate
max_age
}
}
}
Getting cache rules
Use the getCacheConfig
query to view the cache rules that are currently applied.
query getCacheConfig {
getCacheConfig {
rules {
types
stale_while_revalidate
max_age
}
}
}
Updated 8 months ago