Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Memory cache storage + (cache_classes = false) = Weirdness

#639

Patch included:

creates a 'Development' cache storage that changes behavior based on the cache_classes setting

When cache_classes is set to false, much weirdness happens by keeping instances of objects in memory and then wiping/reloading their class definitions out from underneath them. This patch creates a "Development" store that is used by default in the development environment that forces cache misses when cache_classes = false

Reported by David Dollar · July 17th, 2008 @ 04:52 AM

State: invalid
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Pratik
    Pratik
    • State changed from new to invalid
    • Assigned user set to Pratik

    This would only happen if perform_caching is set to true in development mode. Right ?

    July 18th, 2008 @ 01:33 AM

  2. Pratik
    Pratik

    If not, could you please post a test case or something ?

    Thanks.

    July 18th, 2008 @ 01:33 AM

  3. David Dollar
    David Dollar

    It happens with default settings when using Rails.cache

    It may be hard to generate a test case since the problem spans both

    activesupport and actionpack but I'll try.

    --

    David Dollar

    ddollar@gmail.com

    On Jul 17, 2008, at 8:33 PM, Lighthouse

    wrote:

    July 18th, 2008 @ 02:15 AM

  4. Pratik
    Pratik

    Or just paste me the relevant controller/action code from a rails app. Doesn't have to be a test case in Rails test suite.

    Thanks.

    July 18th, 2008 @ 02:24 AM

  5. David Dollar
    David Dollar

    Information about reproducing the failure is here:

    http://pastie.org/236503

    July 18th, 2008 @ 03:54 PM

  6. David Reese
    David Reese

    Not sure why this is marked invalid. This behavior is clearly still happening in edge. David Dollar stated the problem clearly above, but I'll try again to make the case...

    Given the following conditions, common to a dev environment:

    • config.cache_classes = false
    • config.action_controller.perform_caching = false
    • (:memory_store selected by default)

    If you attempt to use Rails.cache.fetch in your application, like this:

    
    
    def index
      @authors = Rails.cache.fetch(:authors) { Author.find(:all) }
    end
    
    

    You will get errors after the first request, either create_time_zone_conversion... or stack level too deep errors (depending on the complexity of your app). These are caused by the combination of Rails.cache caching + cache_classes = false.

    My impression is that when perform_caching = false, caching should not actually be performed, and cache.read should return nil. This is not the case, as David Dollar points out above.

    There are two problems here: 1. perform_caching = false performs caching, which causes problems if cache_classes is off 2. The case of perform_caching = true but cache_classes = false

    It seems we could solve 1. without yet solving 2. In #785 Ryan Bates pointed this out, but the thread was then distracted by the (2) issue.

    Many other tickets (#785, #1290, #1339) talk around this issue but seem to get distracted by the class continuity/caching issue. It's certainly a frustrating issue for anyone trying to add "Rails.cache.fetch"-style caching in the development environment.

    November 11th, 2008 @ 09:20 PM

  7. David Reese
    David Reese

    darn formatting. attaching rest of last comment below.

    You will get errors after the first request, either create_time_zone_conversion... or stack level too deep errors (depending on the complexity of your app). These are caused by the combination of Rails.cache caching + cache_classes = false.

    My impression is that when perform_caching = false, caching should not actually be performed, and cache.read should return nil. This is not the case, as David Dollar points out above.

    There are two problems here: 1. perform_caching = false performs caching, which causes problems if cache_classes is off 2. The case of perform_caching = true but cache_classes = false

    It seems we could solve 1. without yet solving 2. In #785 Ryan Bates pointed this out, but the thread was then distracted by the (2) issue.

    Many other tickets (#785, #1290, #1339) talk around this issue but seem to get distracted by the class continuity/caching issue. It's certainly a frustrating issue for anyone trying to add "Rails.cache.fetch"-style caching in the development environment.

    November 11th, 2008 @ 11:02 PM

  8. David Dollar
    David Dollar

    For anyone that happens to run across this ticket later:

    If you use

    
    @authors = cache(:authors) { Author.find(:all) }
    

    the problem goes away.

    March 11th, 2009 @ 04:11 AM

  9. Brian Armstrong
    Brian Armstrong

    Thanks David for posting that work around. I can confirm that it works, even with memcached parameters like :expires_in.

    For example you can convert this:

    @region = Rails.cache.fetch(current_subdomain, :expires_in=>1.week) do
      Region.find_by_subdomain(current_subdomain)
    end
    

    to this:

    @region = cache(current_subdomain, :expires_in=>1.week) do
      Region.find_by_subdomain(current_subdomain)
    end
    

    And it will start working again.

    This is a pretty big problem and I agree with David Reese, I don't think it should be marked invalid.

    July 25th, 2009 @ 12:45 PM

  10. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 9th, 2010 @ 09:46 PM

  11. Jeff Kreeftmeijer
  12. bingbing