Sha256: fd51fb6dd0f84089689c6308ade1bf0f9ca27ee4785fab43e179c571d8fa3799

Contents?: true

Size: 961 Bytes

Versions: 1

Compression:

Stored size: 961 Bytes

Contents

require 'dalli'

module Legion
  module Cache
    module Memcached
      def connect
        Legion::Logging.debug 'Using Memcached module for Legion::Cache'

        Dalli.logger = Legion::Logging
        @client = Dalli::Client.new(Legion::Settings[:cache][:servers], Legion::Settings[:cache])
        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).positive?
      end

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

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