docs/extensions/parser-cache.md
ParserCacheThis extension adds LRU caching to the parsing step of query execution to improve performance by caching the parsed result in memory.
import strawberry
from strawberry.extensions import ParserCache
@strawberry.type
class Query:
@strawberry.field
def hello(self) -> str:
return "Hello, world!"
schema = strawberry.Schema(
Query,
extensions=[
ParserCache(),
],
)
class ParserCache(maxsize=128): ...
maxsize: Optional[int] = 128Set 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
import strawberry
from strawberry.extensions import ParserCache
@strawberry.type
class Query:
@strawberry.field
def hello(self) -> str:
return "Hello, world!"
schema = strawberry.Schema(
Query,
extensions=[
ParserCache(maxsize=100),
],
)