Class: Twelvefactor::Environment::Cache::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/twelvefactor/environment/cache/redis.rb

Class Method Summary collapse

Class Method Details

.apply(app, cache_url) ⇒ Object



5
6
7
8
9
10
11
12
13
# 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) ⇒ Object



15
16
17
18
19
# 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) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# 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) ⇒ Object



21
22
23
# File 'lib/twelvefactor/environment/cache/redis.rb', line 21

def self.options query
  normalize_types raw_options query
end

.raw_options(query) ⇒ Object



39
40
41
42
43
44
45
46
# 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