Class: ArtirixDataModels::CachedActionAdaptor
- Inherits:
-
Object
- Object
- ArtirixDataModels::CachedActionAdaptor
show all
- Defined in:
- lib/artirix_data_models/cached_action_adaptor.rb
Defined Under Namespace
Classes: Get, GetFull, GetSome
Constant Summary
collapse
- STATUS_OK =
'ok'.freeze
- STATUS_NOT_FOUND =
'not_found'.freeze
- STATUSES =
[STATUS_OK, STATUS_NOT_FOUND]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(logger: nil, cache: nil, **ignored_options) ⇒ CachedActionAdaptor
Returns a new instance of CachedActionAdaptor.
8
9
10
11
12
|
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 8
def initialize(logger: nil, cache: nil, **ignored_options)
@logger = logger || ArtirixDataModels.logger
@cache = cache || ArtirixDataModels.cache
@enabled = true
end
|
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
6
7
8
|
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 6
def cache
@cache
end
|
#logger ⇒ Object
Returns the value of attribute logger.
6
7
8
|
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 6
def logger
@logger
end
|
Instance Method Details
#cached? ⇒ Boolean
14
15
16
17
18
|
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 14
def cached?
return false unless enabled?
cache_exist?
end
|
#disable ⇒ Object
36
37
38
|
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 36
def disable
@enabled = false
end
|
#enable ⇒ Object
32
33
34
|
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 32
def enable
@enabled = true
end
|
#enabled? ⇒ Boolean
40
41
42
|
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 40
def enabled?
@enabled
end
|
#fetch(&block) ⇒ Object
Also known as:
call
20
21
22
23
24
25
26
27
28
|
# File 'lib/artirix_data_models/cached_action_adaptor.rb', line 20
def fetch(&block)
if cached?
get_cached_result
elsif block_given?
perform &block
else
nil
end
end
|