Cache Config
Caching can be configured globally, by type, or field using the configurations below. This gives you an advanced tool for customizing caching behavior, enabling you to fine-tune the settings to optimally meet your project needs.
Global configuration applies caching to all types and fields that are returned by GraphQL queries. This is extremely powerful when used with connectors.
import { config } from '@grafbase/sdk'
export default config({
cache: {
rules: [
{
types: ['Post', 'User'],
},
],
},
})
In the example below we will cache the Post
type and any of its fields for 60 seconds.
import { config, g } from '@grafbase/sdk'
export default config({
cache: {
rules: [
{
types: ['Post'],
maxAge: 60,
},
],
},
})
In the example below we will cache the types and specific fields for 60 seconds.
import { config } from '@grafbase/sdk'
export default config({
cache: {
rules: [
{
types: [
{ name: 'Post', fields: ['title', 'likes'] },
{ name: 'User', fields: ['name', 'email'] },
{ name: 'Comment', fields: ['author', 'body'] },
],
maxAge: 60,
},
],
},
})