-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: updated doc for field and entity caching #104
Conversation
docs/operators/entity_caching.md
Outdated
@@ -0,0 +1,25 @@ | |||
### Entity caching configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can drop this doc.
docs/operators/field_caching.md
Outdated
Field level caching enables caching for any field or query | ||
which contains a resolver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Field level caching enables caching for any field or query | |
which contains a resolver. | |
Field level caching enables caching for any field which contains a resolver. |
docs/operators/field_caching.md
Outdated
type Post { | ||
id: Int | ||
title: String | ||
user_id: Int @cache(maxAge: 100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user_id: Int @cache(maxAge: 100) | |
userId: Int @cache(maxAge: 100) |
docs/operators/field_caching.md
Outdated
id: Int | ||
title: String | ||
user_id: Int @cache(maxAge: 100) | ||
user: User @http(path: "/user/{{user_id}}") @cache(maxAge: 200) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user: User @http(path: "/user/{{user_id}}") @cache(maxAge: 200) | |
user: User @http(path: "/user/{{value.userId}}") @cache(maxAge: 200) |
docs/operators/field_caching.md
Outdated
} | ||
``` | ||
|
||
For the above config, the result of `user` field will be cached because it contains an http resolver. However, the output of `user_id` will not be cached because it doesn't have a resolver for itself, it's value is fetched by the resolver at the `posts` query. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the above config, the result of `user` field will be cached because it contains an http resolver. However, the output of `user_id` will not be cached because it doesn't have a resolver for itself, it's value is fetched by the resolver at the `posts` query. | |
For the above config, the result of `user` field will be cached because it contains an http resolver. However, the output of `userId` & `title` will not be cached because it doesn't have a resolver for itself, it's value is fetched by the resolver at the `posts` field having the `@http(path: "/posts")` directive. |
docs/operators/field_caching.md
Outdated
} | ||
``` | ||
|
||
When the `cache` directive is applied to a type then it is inherited by each of the field of the type. Hence, the above config is equivalent to: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the `cache` directive is applied to a type then it is inherited by each of the field of the type. Hence, the above config is equivalent to: | |
When the `cache` directive is applied to a type then it is inherited by each of the field of the type. Hence, the above config can be reduced into: |
docs/operators/field_caching.md
Outdated
id: Int | ||
title: String | ||
user_id: Int | ||
user: User @http(path: "/user/{{user_id}}") @cache(maxAge: 100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user: User @http(path: "/user/{{user_id}}") @cache(maxAge: 100) | |
user: User @http(path: "/user/{{value.userId}}") @cache(maxAge: 100) |
docs/operators/field_caching.md
Outdated
id: Int | ||
title: String | ||
user_id: Int | ||
user: User @http(path: "/user/{{user_id}}") @cache(maxAge: 100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user: User @http(path: "/user/{{user_id}}") @cache(maxAge: 100) | |
user: User @http(path: "/user/{{value.userId}}") @cache(maxAge: 100) |
docs/operators/field_caching.md
Outdated
} | ||
``` | ||
|
||
### Field level caching implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Field level caching implementation | |
### Implementing Cache Key |
docs/operators/field_caching.md
Outdated
id: Int | ||
title: String | ||
user_id: Int | ||
user: User @http(path: "/user/{{user_id}}") @cache(maxAge: 100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user: User @http(path: "/user/{{user_id}}") @cache(maxAge: 100) | |
user: User @http(path: "/user/{{value.id}}") @cache(maxAge: 100) |
docs/operators/field_caching.md
Outdated
For the config above, field `user` will be cached and the key will be the result of hashing the following values: | ||
* String "Post" | ||
* String "user" | ||
* value of the field `Post.id` | ||
|
||
If `Post` doesn't contain a field `id` or the value isn't present in the response, then the value will not be cached. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation needs to change:
cache
directive to read the resolver applied and use only the arguments on the resolver as key. It should not matter where the resolver is called from, for each query.
For eg: in @http(path: "/users/{{value.id}}")
we should have /users/{{value.id}}
as the key. So for a request made to /users/1
irrespective of where the resolver is attached, we should read from the same cache. For eg: query {todos {user {name}}}
and query {comments {user {name}}}
and query {posts {user {name}}}
should all share the same cache if to resolve user we hit /users
API.
253014e
to
bce8c9c
Compare
bce8c9c
to
f859f99
Compare
Updating documentation for caching