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 any response that has a Post type 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, for 60 seconds, any response that has the fields title or likes from the Post type.

import { config } from '@grafbase/sdk' export default config({ cache: { rules: [ { types: [{ name: 'Post', fields: ['title', 'likes'] }], maxAge: 60, }, ], }, })
Was this page helpful?