Skip to content

Latest commit

 

History

History
72 lines (51 loc) · 1.26 KB

File metadata and controls

72 lines (51 loc) · 1.26 KB
title summary tags
Validation Cache
Add in memory caching to the validation step of query execution.
performance,caching,validation

ValidationCache

This extension adds LRU caching to the validation step of query execution to improve performance by caching the validation errors in memory.

Usage example:

import strawberry
from strawberry.extensions import ValidationCache


@strawberry.type
class Query:
    @strawberry.field
    def hello(self) -> str:
        return "Hello, world!"


schema = strawberry.Schema(
    Query,
    extensions=[
        ValidationCache(),
    ],
)

API reference:

class ValidationCache(maxsize=None): ...

maxsize: Optional[int] = None

Set the maxsize of the cache. If maxsize is set to None then the cache will grow without bound.

More info: https://docs.python.org/3/library/functools.html#functools.lru_cache

More examples:

Using maxsize
import strawberry
from strawberry.extensions import ValidationCache


@strawberry.type
class Query:
    @strawberry.field
    def hello(self) -> str:
        return "Hello, world!"


schema = strawberry.Schema(
    Query,
    extensions=[
        ValidationCache(maxsize=100),
    ],
)