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.

setup_memcache defines CACHE even if disabled:true

#6

setup_memcache (in config.rb) sets the CACHE constant, even if disabled:true is set in memcached.yml.

This is a problem I'd think - I have cases where I want to set arbitrary values to memcached (direct calls to CACHE.set/get), but they're wrapped in a "if defined? CACHE" conditional, so that in development that caching doesn't get done. cache_fu defines CACHE no matter what, which throws off this behavior (and causes an exception when my development memcache server, which i rarely have up, isn't up). at any rate, acts_as_cached didn't do this: it wrapped the Object.const_set(:CACHE... call with a "unless config[:disabled]" conditional.

was there an explicit reason for this? any argument against wrapping the Object.const_set call in a conditional? should i assume CACHE and be checking for something else?

Reported by Oliver Nicholas · May 29th, 2007 @ 11:31 PM

State: hold
Milestone: acts_as_cached 2
Assigned to: Chris Wanstrath Chris Wanstrath

Activity

  1. Chris Wanstrath
    Chris Wanstrath
    • State changed from new to open
    • Assigned user set to Chris Wanstrath
    • Milestone set to acts_as_cached 2

    No good reason for this. I'll see if I can cleanly do what you're suggesting, though it might not be today. If you can send a patch with all the tests still passing that would speed things up on my end.

    May 29th, 2007 @ 11:31 PM

  2. Oliver Nicholas
    Oliver Nicholas

    I mean, I'm open to other suggestions, but I don't think it makes sense for cache_fu to clobber the ability for external code to determine if memcached is supposed to be used. That's just too assumptive for my tastes.

    If CACHE must be set, then the best other option I can think of is to wrap the CACHE.servers= line with the conditional. that way, CACHE.active? will return false since no servers will be added if config[:disabled].

    as for testing it...none of my cache_fu tests will run. they all die on trying to include active_support. i have rails frozen but no gem installed...do i need it?

    May 29th, 2007 @ 11:31 PM

  3. Oliver Nicholas
    Oliver Nicholas

    okay so installing rails as a gem solved the test problem. here's my svn diff, but note that the tests don't pass for me even without making my changes - "should be able to re-raise errors" dies because it can't find a namespace for the CACHE object. I don't know how it works though, cause I don't use a localhost memcached even for development. is that a requirement? seems like it should be mocked out for that purpose.

    also, a point of interest: my revision number for the svn diff are wonky cause i have the plugin installed via piston, so it's a rev from my app's repo, not yours.

    also, it's more or less my job to make this work, so let me know if you want some assistance.

    Index: lib/acts_as_cached/config.rb

    ===================================================================

    --- lib/acts_as_cached/config.rb (revision 7934)

    +++ lib/acts_as_cached/config.rb (working copy)

    @@ -43,19 +43,19 @@

    def setup_memcache(config)

    config[:namespace] << "-#{RAILS_ENV}"

    + silence_warnings do

    + Object.const_set :CACHE, MemCache.new(config)

    + end

    +

    unless config[:disabled]

    - silence_warnings do

    - Object.const_set :CACHE, MemCache.new(config)

    - end

    -

    CACHE.servers = Array(config.delete(:servers))

    setup_session_store if config[:sessions]

    setup_fragment_store! if config[:fragments]

    setup_fast_hash! if config[:fast_hash]

    -

    - CACHE

    end

    +

    + CACHE

    end

    def setup_session_store

    May 29th, 2007 @ 11:31 PM

  4. Oliver Nicholas
  5. Oliver Nicholas
    Oliver Nicholas

    christ i guess there is a <pre>.

    Index: lib/acts_as_cached/config.rb

    ===================================================================

    --- lib/acts_as_cached/config.rb (revision 7934)

    +++ lib/acts_as_cached/config.rb (working copy)

    @@ -43,19 +43,19 @@

    def setup_memcache(config)

    config[:namespace] << "-#{RAILS_ENV}"

    + silence_warnings do

    + Object.const_set :CACHE, MemCache.new(config)

    + end

    +

    unless config[:disabled]

    - silence_warnings do

    - Object.const_set :CACHE, MemCache.new(config)

    - end

    -

    CACHE.servers = Array(config.delete(:servers))

    setup_session_store if config[:sessions]

    setup_fragment_store! if config[:fragments]

    setup_fast_hash! if config[:fast_hash]

    -

    - CACHE

    end

    +

    + CACHE

    end

    def setup_session_store

    May 29th, 2007 @ 11:31 PM

  6. Chris Wanstrath
    Chris Wanstrath

    Alright, I'll try and get this in. http://pastie.caboo.se/ would really work better, I can't cleanly copy and paste this guy easily.

    May 29th, 2007 @ 11:31 PM

  7. Chris Wanstrath
    Chris Wanstrath
    • State changed from open to hold

    May 29th, 2007 @ 11:31 PM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.