diff --git a/object_cache/caching.html b/object_cache/caching.html index 13ed24b0dc..942513ae7b 100644 --- a/object_cache/caching.html +++ b/object_cache/caching.html @@ -280,6 +280,14 @@
If you’re using GraphQL::Schema::Resolver
, you’d call .items_for
slightly differently:
def resolve(division: nil)
+ # use `context[:current_object]` to get the GraphQL::Schema::Object instance whose field is being resolved
+ AllTeams.items_for(context[:current_object], division: division)
+end
+
Finally, you’ll need to handle CacheableRelation
s in your object identification methods, for example:
class MySchema < GraphQL::Schema
@@ -302,12 +310,12 @@ Top-level lists
end
In this example, AllTeams
takes care of integrating with the cache:
In this example, AllTeams
implements several methods to support caching:
#id
to create a cache-friendly, stable global ID#to_param
to create a cache fingerprint (using Rails’s #cache_key
under the hood).find?
to retrieve the list based on its ID#id
creates a cache-friendly, stable global ID#to_param
creates a cache fingerprint (using Rails’s #cache_key
under the hood).find?
retrieves the list based on its IDThis way, if a Team
is created, the cached result will be invalidated and a fresh result will be created.