Sha256: 680f622955cf8e60bc82bd1396b5eef91b1fb67cd0a725c1be2ccb1fac249766

Contents?: true

Size: 822 Bytes

Versions: 1

Compression:

Stored size: 822 Bytes

Contents

require 'memcache'

module CurlyMustache
  module Adapters
    class Memcache < Abstract
      
      def initialize(config)
        config = config.reverse_merge :servers => "localhost:11211"
        @cache = MemCache.new(config[:servers], config)
      end
      
      def get(key)
        (data = @cache.get(key)) and Marshal.load(data)
      end
      
      def mget(keys)
        keys = keys.collect(&:to_s)
        results = @cache.get_multi(*keys)
        results = results.collect{ |k, v| [k, Marshal.load(v)] }
        results.sort.collect{ |result| result[1] }
      end
      
      def put(key, value)
        @cache.set(key, Marshal.dump(value))
      end
      
      def delete(key)
        @cache.delete(key)
      end
      
      def flush_db
        @cache.flush_all
      end
      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cjbottaro-curly_mustache-0.0.0 lib/adapters/memcache.rb