Skip to content

Default cache key produces clashes #491

@samstickland

Description

@samstickland

If there are two cells in the same namespace the same cache will be produced by default, which of course causes all sorts of problems in production.

In caching.rb we have:

def state_cache_key(state, key_parts={})
  expand_cache_key([controller_path, state, key_parts])
end

https://github.com/trailblazer/cells/blob/master/lib/cell/caching.rb#L30

And in cell.rb

def controller_path
  @controller_path ||= File.join(util.underscore(name.sub(/(::Cell.+)/, '')), views_dir)
end

https://github.com/trailblazer/trailblazer-cells/blob/master/lib/trailblazer/cell.rb#L36

This means that a cells called SomeNamespace::Cell::One and SomeNamespace::Cell::Two will produce the same controller_path and hence the same cache key.

I can't see why we simply wouldn't the class name for cache key?

Our workaround for this is currently:

cache :show do
  self.class.name
end

etc.

I think the first code should be:

def state_cache_key(state, key_parts={})
  expand_cache_key([self.class.name, state, key_parts])
end

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