Sha256: 8daa47717101a6f0d9b25cc98846171b5fc5f851ddb1038e41bef775f8264863

Contents?: true

Size: 865 Bytes

Versions: 2

Compression:

Stored size: 865 Bytes

Contents

module Suo
  module Client
    class Memcached < Base
      def initialize(key, options = {})
        options[:client] ||= Dalli::Client.new(options[:connection] || ENV["MEMCACHE_SERVERS"] || "127.0.0.1:11211")
        super
      end

      def clear
        @client.with { |client| client.delete(@key) }
      end

      private

      def get
        @client.with { |client| client.get_cas(@key) }
      end

      def set(newval, cas, expire: false)
        if expire
          @client.with { |client| client.set_cas(@key, newval, cas, @options[:ttl]) }
        else
          @client.with { |client| client.set_cas(@key, newval, cas) }
        end
      end

      def initial_set(val = BLANK_STR)
        @client.with do |client|
          client.set(@key, val)
          _val, cas = client.get_cas(@key)
          cas
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
suo-0.4.0 lib/suo/client/memcached.rb
suo-0.3.4 lib/suo/client/memcached.rb