Sha256: 8512d948466f782fc989f51d2aa04425f6b8e9f593766be2bbf55e1964110af1

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'dalli'

module Legion
  module Cache
    module Memcached
      def connect
        Legion::Logging.debug 'Using Memcached module for Legion::Cache'
        options = { compress:  true,
                    serializer: Legion::JSON,
                    failover:  Legion::Settings[:cache][:failover],
                    namespace: Legion::Settings[:cache][:namespace], foo: 'test' }
        Dalli.logger = Legion::Logging
        @client = Dalli::Client.new(Legion::Settings[:cache][:servers], options)
        Legion::Logging.debug "Legion::Cache successfully connected to #{Legion::Settings[:cache][:servers]}"
        Legion::Settings[:cache][:connected] = true
      end

      def close
        @client.close
      end

      def restart
        close
        connect
      end

      def get(key)
        @client.get(key)
      end

      def fetch(key, ttl = nil)
        @client.fetch(key, ttl)
      end

      def set(key, value, ttl = 180)
        @client.set(key, value, ttl)
      end

      def delete(key)
        @client.delete(key)
      end

      def flush(delay = 0)
        @client.flush(delay)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
legion-cache-0.2.0 lib/legion/cache/memcached.rb