Module: ResponseBank
- Defined in:
- lib/response_bank.rb,
lib/response_bank/railtie.rb,
lib/response_bank/version.rb,
lib/response_bank/controller.rb,
lib/response_bank/middleware.rb,
lib/response_bank/model_extensions.rb,
lib/response_bank/response_cache_handler.rb
Defined Under Namespace
Modules: Controller, ModelExtensions
Classes: Middleware, Railtie, ResponseCacheHandler
Constant Summary
collapse
- VERSION =
"1.2.0"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.cache_store ⇒ Object
Returns the value of attribute cache_store.
9
10
11
|
# File 'lib/response_bank.rb', line 9
def cache_store
@cache_store
end
|
.logger=(value) ⇒ Object
Sets the attribute logger
10
11
12
|
# File 'lib/response_bank.rb', line 10
def logger=(value)
@logger = value
end
|
Class Method Details
.acquire_lock(_cache_key) ⇒ Object
16
17
18
|
# File 'lib/response_bank.rb', line 16
def acquire_lock(_cache_key)
raise NotImplementedError, "Override ResponseBank.acquire_lock in an initializer."
end
|
.cache_key_for(data) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/response_bank.rb', line 45
def cache_key_for(data)
case data
when Hash
return data.inspect unless data.key?(:key)
key = hash_value_str(data[:key])
key = %{#{data[:key_schema_version]}:#{key}} if data[:key_schema_version]
key = %{#{key}:#{hash_value_str(data[:version])}} if data[:version]
key
when Array
data.inspect
when Time, DateTime
data.to_i
when Date
data.to_s when true, false, Integer, Symbol, String
data.inspect
else
data.to_s.inspect
end
end
|
.compress(content) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/response_bank.rb', line 32
def compress(content)
io = StringIO.new
gz = Zlib::GzipWriter.new(io)
gz.write(content)
io.string
ensure
gz.close
end
|
.decompress(content) ⇒ Object
41
42
43
|
# File 'lib/response_bank.rb', line 41
def decompress(content)
Zlib::GzipReader.new(StringIO.new(content)).read
end
|
.log(message) ⇒ Object
12
13
14
|
# File 'lib/response_bank.rb', line 12
def log(message)
@logger.info("[ResponseBank] #{message}")
end
|
.read_from_backing_cache_store(_env, cache_key, backing_cache_store: cache_store) ⇒ Object
28
29
30
|
# File 'lib/response_bank.rb', line 28
def read_from_backing_cache_store(_env, cache_key, backing_cache_store: cache_store)
backing_cache_store.read(cache_key, raw: true)
end
|
.write_to_backing_cache_store(_env, key, payload, expires_in: nil) ⇒ Object
24
25
26
|
# File 'lib/response_bank.rb', line 24
def write_to_backing_cache_store(_env, key, payload, expires_in: nil)
cache_store.write(key, payload, raw: true, expires_in: expires_in)
end
|
.write_to_cache(_key) ⇒ Object
20
21
22
|
# File 'lib/response_bank.rb', line 20
def write_to_cache(_key)
yield
end
|