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 strawberryfrom strawberry.extensions import ValidationCache
@strawberry.typeclass Query: @strawberry.field def hello(self) -> str: return "Hello, world!"
schema = strawberry.Schema( Query, extensions=[ ValidationCache(), ],) API reference:
class ValidationCache(maxsize=128): ... maxsize: Optional[int] = 128
Set the maxsize of the cache. By default the cache is bounded to 128 entries,
with the least recently used entries evicted first. Pass an explicit
maxsize=None to let the cache grow without bound; only do this when the set of
distinct query texts reaching the server is trusted and bounded, as an unbounded
cache lets clients grow the serverβs memory indefinitely by sending unique query
texts.
More info: https://docs.python.org/3/library/functools.html#functools.lru_cache
More examples:
Using maxsize
import strawberryfrom strawberry.extensions import ValidationCache
@strawberry.typeclass Query: @strawberry.field def hello(self) -> str: return "Hello, world!"
schema = strawberry.Schema( Query, extensions=[ ValidationCache(maxsize=100), ],)