Class: Suitcase::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/suitcase/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ Cache

Returns a new instance of Cache



5
6
7
# File 'lib/suitcase/cache.rb', line 5

def initialize(store)
  @store = store
end

Instance Attribute Details

#storeObject

Returns the value of attribute store



3
4
5
# File 'lib/suitcase/cache.rb', line 3

def store
  @store
end

Instance Method Details

#cached?(action, params) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/suitcase/cache.rb', line 26

def cached?(action, params)
  @store[action] && @store[action][params]
end

#get_query(action, params) ⇒ Object



18
19
20
# File 'lib/suitcase/cache.rb', line 18

def get_query(action, params)
  @store[action] ? @store[action][params] : nil
end

#keysObject



22
23
24
# File 'lib/suitcase/cache.rb', line 22

def keys
  @store.keys
end

#save_query(action, params, response) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/suitcase/cache.rb', line 9

def save_query(action, params, response)
  %w(apiKey cid customerSessionId customerIpAddress locale customerUserAgent).each do |param|
    params.delete(param)
  end
  params.delete("currencyCode") unless action == :paymentInfo
  @store[action] ||= {}
  @store[action][params] = response
end

#undefine_query(action, params) ⇒ Object



30
31
32
# File 'lib/suitcase/cache.rb', line 30

def undefine_query(action, params)
  @store[action].delete(params) if @store[action]
end