This repository was archived by the owner on Oct 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Advanced custom cache keys #52
Copy link
Copy link
Open
Labels
Description
I am not sure that this is a good idea. I will need to think more about that tomorrow or if I even actually need to to this. But here is my idea dump right now for future reference.
My use case is that my custom cache key value is potentially complicated and would need:
-
a lambda/proc on multiple lines (not super elegant, but already possible?)
field :some_field, String, cache: { key: ->(obj) { "#{obj.id}123blah" } } do ... end
-
its own line, e.g.
field :calculated_field, Int do cache <complicated code block goes here> end
-
or even its own method within the enclosing Type class.
field :calculated_field, Int, cache: { key: :custom_cache_key }
where
:custom_cache_keyis first looked up in the instance of the enclosing type class that is defining this field (withrespond_to?) and only then calls the parentobjectif it's not defined. -
or just use
Rails.cache.fetchblocks manually inside the resolver