class WebFetch::Storage::Memcached
Public Class Methods
new(client = nil)
click to toggle source
# File lib/web_fetch/storage/memcached.rb, line 6 def initialize(client = nil) require 'dalli' if client.nil? @client = client || Dalli::Client @config = { host: ENV.fetch('WEB_FETCH_MEMCACHED_HOST', 'localhost'), port: ENV.fetch('WEB_FETCH_MEMCACHED_PORT', '11211') } end
Public Instance Methods
delete(key)
click to toggle source
# File lib/web_fetch/storage/memcached.rb, line 26 def delete(key) storage.delete(key) end
fetch(key)
click to toggle source
# File lib/web_fetch/storage/memcached.rb, line 19 def fetch(key) result = storage.get(key) return JSON.parse(result, symbolize_names: true) unless result.nil? nil end
store(key, obj)
click to toggle source
# File lib/web_fetch/storage/memcached.rb, line 15 def store(key, obj) storage.set(key, obj.to_json) end
Private Instance Methods
storage()
click to toggle source
# File lib/web_fetch/storage/memcached.rb, line 32 def storage @storage ||= begin host = @config.fetch(:host) port = @config.fetch(:port) @client.new("#{host}:#{port}", expires_in: ttl) end end
ttl()
click to toggle source
# File lib/web_fetch/storage/memcached.rb, line 40 def ttl @ttl ||= ENV.fetch('WEB_FETCH_MEMCACHED_TTL', '60').to_i end