trailblazer / cells

View components for Ruby and Rails.
https://trailblazer.to/2.1/docs/cells.html
3.07k stars 236 forks source link

[Question] calling `cache` method for a "state" will overwrite settings in previous call? #351

Closed PikachuEXE closed 7 years ago

PikachuEXE commented 9 years ago

I got something like this in a concept cell:

cache(
      :show,
      :cache_key,
      expires_in: 1.hour,
      if: :should_be_cached_hourly,
    )
    cache(
      :show,
      :cache_key,
      expires_in: 1.day,
      if: :should_be_cached_daily,
    )
    cache(
      :show,
      :cache_key,
      expires_in: 1.month,
      if: :should_be_cached_monthly,
    )

I want to cache the the cell hourly / daily / monthly based on a model attribute value (which is a time) But it seems the caching occurs when should_be_cached_monthly is true This is discovered by caching spec not failing when the method name for cache key is wrong

apotonick commented 9 years ago

I am pretty sure you can call cache only once, or when multiple times, the last one wins. We could think about making the options dynamic, e.g. ->(options) { expires_in: logic_to_find_out }.