Sha256: ffd980a3aaa74d74455899f36366719d5ffda4268699b380c15fe4d3387011cc

Contents?: true

Size: 890 Bytes

Versions: 10

Compression:

Stored size: 890 Bytes

Contents

begin
  require "memcached"
rescue LoadError
  require "memcache"
rescue LoadError
  puts "You need the memcache gem to use the Memcache moneta store"
  exit
end

module Moneta
  class Memcache
    include Defaults
    
    def initialize(options = {})
      @cache = MemCache.new(options.delete(:server), options)
    end

    def key?(key)
      !self[key].nil?
    end

    alias has_key? key?

    def [](key)
      @cache.get(key)
    end

    def []=(key, value)
      store(key, value)
    end

    def delete(key)
      value = self[key]
      @cache.delete(key) if value
      value
    end

    def store(key, value, options = {})
      args = [key, value, options[:expires_in]].compact
      @cache.set(*args)
    end

    def update_key(key, options = {})
      val = self[key]
      self.store(key, val, options)
    end

    def clear
      @cache.flush_all
    end
  end
end

Version data entries

10 entries across 10 versions & 7 rubygems

Version Path
aeden-moneta-0.6.2 lib/moneta/memcache.rb
aeden-moneta-0.6.3 lib/moneta/memcache.rb
benschwarz-smoke-0.5.7 vendor/gems/gems/wycats-moneta-0.6.0/lib/moneta/memcache.rb
jferris-moneta-0.6.2 lib/moneta/memcache.rb
jsl-moneta-0.6.1 lib/moneta/memcache.rb
jsl-moneta-0.6.2 lib/moneta/memcache.rb
jsl-moneta-0.6.3 lib/moneta/memcache.rb
smurphy-moneta-0.6.0 lib/moneta/memcache.rb
wycats-moneta-0.6.0 lib/moneta/memcache.rb
moneta-0.6.0 lib/moneta/memcache.rb