Module: Akeneo::Cache

Included in:
ServiceBase
Defined in:
lib/akeneo/cache.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DEFAULT_EXPIRES_IN =
5 * 60
@@disabled =

rubocop:disable Style/ClassVars

false

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.disabled=(value) ⇒ Object



11
12
13
# File 'lib/akeneo/cache.rb', line 11

def self.disabled=(value)
  @@disabled = value # rubocop:disable Style/ClassVars
end

.prepended(base) ⇒ Object



21
22
23
# File 'lib/akeneo/cache.rb', line 21

def self.prepended(base)
  base.extend(ClassMethods)
end

Instance Method Details

#get_request(path, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/akeneo/cache.rb', line 25

def get_request(path, options = {})
  return super if disabled?

  key = path.downcase
  key << options[:query].to_s if defined? options[:query]

  cached_response = read(key)
  return cached_response unless cached_response.nil?

  response = super

  write(key, response)
  response
rescue Redis::CannotConnectError
  super
end