Skip to content

Include arguments as part of cache_key in custom preloads #172

@mintuhouse

Description

@mintuhouse

There may be cases where we want to preload instance methods which accept arguments
e.g.,

def custom_count(condition)
   goldiload("custom_count_#{condition.inspect}") do |ids|
     # logic to return condition based counts for all ids
   end
end
Model.all do |m|
  m.custom_count(condition1) # Would fire a single query for all model instances
  m.custom_count(condition2) # Would fire another query for all model instances
end
  • Are there any downsides to including it that way
  • If its ok to do so, thinking if passing another optional kwarg cache_args = [] which can be appended to existing cache_key in
    cache_name ||= block.source_location.join(':')
    make its usage obvious to future users of that API

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions