-
Notifications
You must be signed in to change notification settings - Fork 32
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
Clarification on cache_key options #98
Comments
Hey! The difference is that when you pass only argument (second snippet) it will be used both for building the cache key and as a value for caching, and when you pass an argument and a block — it will build the key using object but return the value. For instance, imagine that post somehow depends on the user. In this case you might want to cache the post for this particular user, not for everyone: def post(id:)
post = Post.find(id)
cache_fragment([post, current_user]) { post }
end In case of |
Sorry for being obtuse here, but its still not clear from the documentation what the difference between |
@gsdean but the explanation above is more clear, right? |
Sadly no, I think what would be helpful is to clarify the difference in terms of just the attribute without overriding the getter. In other words, what is the difference between:
and
? |
Also not to hijack the thread, but have you seen this #72 (comment) There is a pretty serious race condition that we should probably address. |
When For instance impagine a post that has the author, and for some reason we want author cache to be refreshed only when post is updated. In this case we can do this: class Post
field :cached_author, Types::User, null: true, cache_fragment: {cache_key: :object}
def cached_author
object.author
end
end
class Query < Base
field :post, Post, null: true do
argument :id, GraphQL::Types::ID, required: true
end
def post(id:)
::Post.find(id)
end
end If you keep this code as is than The same thing but in code https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/blob/master/spec/graphql/fragment_cache/field_extensions_spec.rb#L171. |
Maybe it's just me, but I find the readme on this really confusing.
[README]
When using cache_fragment: option, it's only possible to use the resolved value as a cache key by setting:
Also, you can pass :value to the cache_key: argument to use the returned value to build a key:
[/README]
What is the difference between the "resolved value" being used vs. the "returned value"?
Also, it's not immediately clear how
AND
Are different.
The text was updated successfully, but these errors were encountered: