class Twelvefactor::Environment::Cache::Redis

Public Class Methods

apply(app, cache_url) click to toggle source
# File lib/twelvefactor/environment/cache/redis.rb, line 5
def self.apply app, cache_url
  config = app.config

  config.cache_store = [
    :redis_store,
    cache_base_url(cache_url).to_s,
    options(cache_url.query)
  ]
end
cache_base_url(url) click to toggle source
# File lib/twelvefactor/environment/cache/redis.rb, line 15
def self.cache_base_url url
  base = url.dup
  base.query = nil
  base
end
normalize_types(options) click to toggle source
# File lib/twelvefactor/environment/cache/redis.rb, line 25
def self.normalize_types options
  normalized = {}

  if options.key? :expires_in
    normalized[:expires_in] = options[:expires_in].to_i
  end

  if options.key? :compress
    normalized[:compress] = options[:compress] == "true"
  end

  options.merge normalized
end
options(query) click to toggle source
# File lib/twelvefactor/environment/cache/redis.rb, line 21
def self.options query
  normalize_types raw_options query
end
raw_options(query) click to toggle source
# File lib/twelvefactor/environment/cache/redis.rb, line 39
def self.raw_options query
  return {} unless query

  CGI
    .parse(query)
    .map { |k, val| [k.to_sym, val.first] }
    .to_h
end