Skip to content

Commit

Permalink
Memcached layer is in play but still not behaving. Must clone and des…
Browse files Browse the repository at this point in the history
…troy, but the clone claims it doesn't have a method destroy.
  • Loading branch information
ab5tract committed Sep 23, 2008
1 parent 842bd3a commit efd87cc
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions lib/layers/cache/memcached/memcached-ipi.rb
Expand Up @@ -12,34 +12,24 @@ def initialize(args)
@cache = ::Memcached.new(args[:servers], args[:opt])
end

def add(key,value, ttl = 0, marshal = true)
@cache.add(key.to_s,value,ttl,marshal)
def store(key,value, ttl = 0, marshal = true)
Waves.synchronize { cache = @cache.clone; cache.add(key.to_s,value,ttl,marshal); cache.destroy }
end

def get(key)
@cache.get(key.to_s)
def fetch(key)
Waves.synchronize { cache = @cache.clone; cache.get(key.to_s); cache.destroy }
rescue ::Memcached::NotFound => e
# In order to keep the Memcached layer compliant with Waves::Cache...
# ...we need to be able to expect that an absent key raises KeyMissing
raise KeyMissing, "#{key} doesn't exist, #{e}"
end

def delete(*keys)
keys.each {|key| @cache.delete(key.to_s) }
keys.each {|key| Waves.synchronize { cache = @cache.clone; cache.delete(key.to_s) }; cache.destroy }
end

def clear
@cache.flush
end

alias_method :store, :add # Override our natural Waves::Cache :store method with Memcache's :add
alias_method :fetch, :get # Override our natural Waves::Cache :fetch method with Memcache's :get

def method_missing(*args, &block)
@cached.__send__(*args, &block)
rescue => e
Waves::Logger.error e.to_s
nil
Waves.synchronize { cache = @cache.clone; cache.flush; cache.destroy }
end

end
Expand Down

0 comments on commit efd87cc

Please sign in to comment.