class RdCache

Public Class Methods

cache_exists?() click to toggle source
# File lib/caches/rd_cache.rb, line 20
def cache_exists?
  Net::HTTP.get(URI("http://#{@@config['host']}"))
rescue Errno::ECONNREFUSED => error
  puts "**** Error: #{error.message}"
  @@client = nil
rescue Net::HTTPBadResponse => error
  # do nothing
end
client() click to toggle source
# File lib/caches/rd_cache.rb, line 7
def client
  @@client
end
delete(key, options = {}) click to toggle source
# File lib/caches/rd_cache.rb, line 42
def delete(key, options = {})
  return unless client
  deleted = read(key)
  client.del(key)
  deleted
end
initialize() click to toggle source
# File lib/caches/rd_cache.rb, line 11
def initialize
  @@config ||= ConfigService.load_config('redis.yml')[ConfigService.environment]
  @@client ||= Redis.new(url: "redis://#{@@config['host']}")
  cache_exists?
rescue Exception => error
  puts("RdCache.initialize error: #{error.message}")
  @@client = nil
end
read(key, options = {}) click to toggle source

Cache API, mimics ActiveSupport::Cache::Store api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html

# File lib/caches/rd_cache.rb, line 31
def read(key, options = {})
  return unless client
  client.get(key)
end
write(key, value, options = {}) click to toggle source
# File lib/caches/rd_cache.rb, line 36
def write(key, value, options = {})
  return unless client
  client.set(key, value)
  client.expire(key, options[:expires_in]) if  options[:expires_in]
end