Skip to content
This repository was archived by the owner on Oct 26, 2022. It is now read-only.
This repository was archived by the owner on Oct 26, 2022. It is now read-only.

Advanced custom cache keys #52

@jeromedalbert

Description

@jeromedalbert

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_key is first looked up in the instance of the enclosing type class that is defining this field (with respond_to?) and only then calls the parent object if it's not defined.

  • or just use Rails.cache.fetch blocks manually inside the resolver

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions