module Legion::Cache::Memcached
Public Instance Methods
client(servers: Legion::Settings[:cache][:servers], **opts)
click to toggle source
# File lib/legion/cache/memcached.rb, line 10 def client(servers: Legion::Settings[:cache][:servers], **opts) return @client unless @client.nil? @pool_size = opts.key?(:pool_size) ? opts[:pool_size] : Legion::Settings[:cache][:pool_size] || 10 @timeout = opts.key?(:timeout) ? opts[:timeout] : Legion::Settings[:cache][:timeout] || 5 Dalli.logger = Legion::Logging @client = ConnectionPool.new(size: pool_size, timeout: timeout) do Dalli::Client.new(servers, Legion::Settings[:cache].merge(opts)) end @connected = true @client end
delete(key)
click to toggle source
# File lib/legion/cache/memcached.rb, line 37 def delete(key) client.with { |conn| conn.delete(key) == true } end
fetch(key, ttl = nil)
click to toggle source
# File lib/legion/cache/memcached.rb, line 29 def fetch(key, ttl = nil) client.with { |conn| conn.fetch(key, ttl) } end
flush(delay = 0)
click to toggle source
# File lib/legion/cache/memcached.rb, line 41 def flush(delay = 0) client.with { |conn| conn.flush(delay).first } end
get(key)
click to toggle source
# File lib/legion/cache/memcached.rb, line 25 def get(key) client.with { |conn| conn.get(key) } end
set(key, value, ttl = 180)
click to toggle source
# File lib/legion/cache/memcached.rb, line 33 def set(key, value, ttl = 180) client.with { |conn| conn.set(key, value, ttl).positive? } end