-
Notifications
You must be signed in to change notification settings - Fork 25
Advanced custom cache keys #52
Comments
@jeromedalbert thanks for pointing this out. There seems to be a use case that we don't really cover with overridden keys. Looking through the code, I'm starting to think the whole key construct could be refactored to be a bit more readable and maintainable. I'm going to open a PR later today to start off that process. I'm thinking maybe break key up somehow along the lines of type as evaluated here Identify the type of key based on |
Starting up a refactor over on #50 that will fix that specific issue along with making it possible to provide a custom key generation class of some kind which will give you all the tools necessary for controlling the cache keys for specific fields. |
I hope this issue is not too much of a hassle or waste of time, because I don't find myself often needing this. If it is a hassle, feel free to close! Maybe needing complicated cache keys is a code smell telling me to instead cache upstream (Rails fragment/page caching), cache downstream (plain |
Though it's not often used, I think the current implementation is a little stilted in it's flexibility. I think a feature like |
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?)
its own line, e.g.
or even its own method within the enclosing Type class.
where
:custom_cache_key
is first looked up in the instance of the enclosing type class that is defining this field (withrespond_to?
) and only then calls the parentobject
if it's not defined.or just use
Rails.cache.fetch
blocks manually inside the resolverThe text was updated successfully, but these errors were encountered: