tailcall icon indicating copy to clipboard operation
tailcall copied to clipboard

Improvements for cache implementation

Open shashitnak opened this issue 1 year ago • 1 comments

Problem description In the current cache implementation, if @cache is added to fields of a type and not to the query where it is being resolved then the values doesn't get cached.

type Query {
  posts: [Post] @http(path: "/posts")
}

type Post {
  id: Int! @cache(maxAge: 3000)
  userId: Int! @cache(maxAge: 4000)
  title: String!
  body: String!
  user: User @http(path: "/users/{{value.userId}}")
}

The above config will not result in any form of caching.

type Query {
  posts: [Post] @http(path: "/posts") @cache(maxAge: 3000)
}

type Post {
  id: Int!
  userId: Int!
  title: String!
  body: String!
  user: User @http(path: "/users/{{value.userId}}")
}

This config, however, will cache the result of posts query.

Solution One of the ways of fixing this issue is to do the following:

  • Add a field in ServerContext to hold the values provided by @cache directive for whichever field it is added to.
  • While creating the resolver function in src/blueprint/into_schema.rs use the field.of_type.name to get the type of output and use it to determine what caching rules are applied to the type and the fields of that type and use them to decide what values to fetch and what already exist in the cache.

shashitnak avatar Dec 29 '23 12:12 shashitnak

@tusharmath I want to work on this one

melsonic avatar Dec 29 '23 14:12 melsonic

Action required: Issue inactive for 30 days. Status update or closure in 7 days.

github-actions[bot] avatar Feb 28 '24 13:02 github-actions[bot]

Issue closed after 7 days of inactivity.

github-actions[bot] avatar Mar 06 '24 13:03 github-actions[bot]