#6 ✓hold
Oliver Nicholas

setup_memcache defines CACHE even if disabled:true

Reported by Oliver Nicholas | May 29th, 2007 @ 11:31 PM | in acts_as_cached 2

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?

Comments and changes to this ticket

  • Chris Wanstrath

    Chris Wanstrath May 29th, 2007 @ 11:31 PM

    • 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.

  • Oliver Nicholas

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

    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?

  • Oliver Nicholas

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

    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

  • Oliver Nicholas
  • Oliver Nicholas

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

    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

  • Chris Wanstrath

    Chris Wanstrath May 29th, 2007 @ 11:31 PM

    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.

  • Chris Wanstrath

    Chris Wanstrath May 29th, 2007 @ 11:31 PM

    • State changed from “open” to “hold”

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Shared Ticket Bins

People watching this ticket

Tags

Pages