From a35478f77528b4237fd697f4a2a91427c096628a Mon Sep 17 00:00:00 2001 From: Shashi Kant Date: Wed, 27 Dec 2023 00:07:23 +0530 Subject: [PATCH] adding description for maxAge and description of how caching works --- docs/operators/cache.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/operators/cache.md b/docs/operators/cache.md index 2337917bb9..7e13385db8 100644 --- a/docs/operators/cache.md +++ b/docs/operators/cache.md @@ -28,4 +28,12 @@ type User @cache(maxAge: 4000) { } ``` +## maxAge + +the parameter `maxAge` takes a non-zero unsigned integer value which signifies the duration, in milliseconds, for which the value will be cached. + In the above example, the entire result of `posts` query will be cached for 3000ms. When the **@cache** operator is applied to a type, it is equivalent to applying it to each field individually. If for a type, one of the fields needs to be cached differently then this operator can be applied to that field separately and it will override the values provided for the type, as can be seen in the above example for `name` field in the `User` type. + +# How does the caching work? + +If **@cache** is set for a query or a field, the resolver for it will run once and the result will be stored in memory for `maxAge` milliseconds, and will expire after this duration. After the cache expires, the resolver will be run again to fetch the latest value and that value will then be cached.