Module: HeuristicCache
- Defined in:
- lib/heuristic_cache/cache_helper.rb,
lib/heuristic_cache/heuristic_cache.rb
Defined Under Namespace
Modules: Helpers
Classes: Coefficient, TTL
Constant Summary
collapse
- CACHEABLE_STATUSES =
Array.new
Class Method Summary
collapse
Class Method Details
.cacheable?(object) ⇒ Boolean
32
33
34
|
# File 'lib/heuristic_cache/heuristic_cache.rb', line 32
def self.cacheable?(object)
CACHEABLE_STATUSES.empty? ? true : object.respond_to?(:status) && CACHEABLE_STATUSES.include?(object.status)
end
|
.init(file, env = 'development') ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/heuristic_cache/heuristic_cache.rb', line 6
def self.init(file, env = 'development')
raise ArgumentError, '[HEURISTIC_CACHE] Param env is required' if env == nil
raise ArgumentError, '[HEURISTIC_CACHE] Param file (path config file) is required' if file == nil
raise ArgumentError, '[HEURISTIC_CACHE] Param file (path config file) is invalid' unless File.exists?(file)
yml = ::Commons::Yml.read(file)
raise ArgumentError, "[HEURISTIC_CACHE] Config for ENV (#{env}) not found" unless yml[env]
config = yml[env]['cache_config']
STDOUT.puts '[HEURISTIC_CACHE] WARNING: attr time_to_live is required' if config["time_to_live"] == nil
TTL.init(config["time_to_live"])
STDOUT.puts '[HEURISTIC_CACHE] WARNING: attr coefficient is required' if config["coefficient"] == nil
Coefficient.init(config["coefficient"])
CACHEABLE_STATUSES.concat(config["cacheable_statuses"])
nil
end
|