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.

[PATCH] Add a NullStore to ActiveSupport::Cache

#1367

With the config action_controller.perform_caching = false, action controller still tries to use the cache_store to perform Rails.cache.- style caching. This is surprising behavior.

Either:

  1. The config setting should be renamed to be clear about what you are controlling, or preferably,
  2. Rails.cache.read should return nil when perform_caching is false. cache.read returning nil should already be handled by the application.

There is already a protected "convenience accessor" (Cache#cache) that uses cache_configured? to give this (2) actual behavior, yielding the block when caching is not set up.

Tickets #639, #785, and #1290 all dance around this issue -- #639 is marked 'invalid', and #785 and #1290 are marked as dupes of #1339. In development, being able to actually turn off caching while leaving cache_classes = false would solve many of these issues for common use scenarios.

Reported by David Reese · November 13th, 2008 @ 02:06 PM

State: stale
Milestone: 3.x
Assigned to: Michael Koziarski Michael Koziarski
Importance: none

Activity

  1. Doug Cole
    Doug Cole

    I just spend 30 minutes trying to figure this out too, when starting to use Rails.cache. If no one is working on this I'll write a patch - looks pretty simple.

    March 13th, 2009 @ 09:21 PM

  2. CancelProfileIsBroken
  3. John Pignata
    John Pignata

    Since the Rails.cache functionality exists in ActiveSupport and not ActionController, I propose a new configuration setting of config.active_support.perform_caching= with a default of true.

    The patch adds this behavior to Active Support and also modifies the stores to honor the setting. exists? and read will return false and nil respectively when perform caching is set to false. Feedback?

    August 9th, 2009 @ 05:42 AM

  4. John Pignata
    John Pignata
    • Tag changed from bugmash to bugmash, patch
    • Title changed from Perform caching=false should not perform caching to [PATCH] Perform caching=false should not perform caching

    August 9th, 2009 @ 03:18 PM

  5. Derander
    Derander

    +1, this seems like an appropriate change. Shouldn't break backwards compatibility.

    Applies cleanly to latest master & tests pass.

    August 10th, 2009 @ 07:37 AM

  6. David Reese
    David Reese
    • Title changed from [PATCH] Perform caching=false should not perform caching to [PATCH] ActiveSupport should have a "perform_caching=false" setting

    Ok, now I get that when you say "action_controller.perform_caching = false", you're turning off page, action, and fragment caching, not all caching that happens in your controllers. Somehow that was not clear to me.

    But, +1 on John's patch -- there should be some way to also turn off ActiveSupport caching, and the patch does that ably.

    One thing I would change for cleanliness -- I'd set @@perform_caching=true first, which seems to be common practice in Rails. The section where @@perform_caching is checked for nil seemed a little opaque:


    {mkd-extraction-e508fd6e2a88aa82336506488855005a}

    I'd add this, and then you don't need to check for nil in #cache_configured?, just return perform_caching:

    + @@perform_caching = true

    {mkd-extraction-d4304b7970b636c816dabf43df1f88e0}

    I tried to make a new patch but it seemed to add my patch onto John's patch. If there's a cleaner way to to that someone should probably go ahead and do it.

    August 15th, 2009 @ 03:08 PM

  7. John Pignata
    John Pignata
    • Tag changed from bugmash, patch to activesupport, bugmash, cache, patch

    Good feedback - thanks, David. Attached is a patch with your feedback that will apply to master.

    August 15th, 2009 @ 11:33 PM

  8. John Pignata
  9. John Pignata
    John Pignata

    For good measure, here's a patch for 2.3 stable if it's desired to get this in prior to 3.0

    August 16th, 2009 @ 12:07 AM

  10. John Pignata
    John Pignata
    • Title changed from [PATCH] ActiveSupport should have a "perform_caching=false" setting to [PATCH] Add a NullStore to ActiveSupport::Cache
    • Assigned user set to Michael Koziarski

    Talked to nzkoz who was of the opinion that this patch should instead be a null store that users could implement for edge cases in debugging and testing. This makes sense and is more flexible than a configuration setting. Attached is a patch to add a null store to master.

    September 27th, 2009 @ 03:12 AM

  11. Elad Meidar
    Elad Meidar

    +1 verified and nailed :) Looks like it's a well respected behavior, latest patch applies cleanly on latest master.

    September 27th, 2009 @ 03:31 AM

  12. David Reese
    David Reese

    What about "BlackholeStore" instead? It's so much more poetic. (There's some reason we're not python developers, right?)

    September 27th, 2009 @ 03:32 AM

  13. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from activesupport, bugmash, cache, patch to activesupport, bugmash, bugmash-review, cache, patch

    September 27th, 2009 @ 11:34 AM

  14. John Pignata
    John Pignata

    Any additional feedback on this feature?

    December 21st, 2009 @ 01:18 AM

  15. Rizwan Reza
    Rizwan Reza
    • Tag changed from activesupport, bugmash, bugmash-review, cache, patch to activesupport, bugmash-review, cache, patch

    February 12th, 2010 @ 12:46 PM

  16. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  17. Rizwan Reza
    Rizwan Reza
    • Tag changed from activesupport, bugmash-review, cache, patch to activesupport, bugmash, cache, patch

    May 15th, 2010 @ 06:45 PM

  18. Simon Jefford
    Simon Jefford
    • Tag changed from activesupport, bugmash, cache, patch to activesupport, bugmash, bugmash-review, cache, patch

    I've rebased the above patch, cleaned up some whitespace issues and updated it slightly so overrides the correct methods (they seem to have changed slightly from when this patch was submitted).

    The original authorship has been retained in the patch.

    +1 verified

    May 15th, 2010 @ 10:22 PM

  19. Simon Jefford
    Simon Jefford

    Updated patch - more test coverage + remove unnecessary override

    May 15th, 2010 @ 11:45 PM

  20. Rizwan Reza
    Rizwan Reza
    • Tag changed from activesupport, bugmash, bugmash-review, cache, patch to activesupport, bugmash, cache, patch
    • State changed from new to open

    We still need some +1s here.

    May 16th, 2010 @ 02:25 AM

  21. Peter Marklund
    Peter Marklund

    I like this patch as it enabled global disabling of the cache. To me it would make sense to have an enabled attribute on the Rails.cache object, something I achieved with a monkey patch:

    http://developer.newsdesk.se/2010/05/04/enablingdisabling-the-rails...

    June 15th, 2010 @ 03:32 PM

  22. Santiago Pastorino
    Santiago Pastorino
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:37 PM

  23. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:37 PM