Class: Heartcheck::CachingApp::Cache

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

Overview

This cache performs the given controllers in background threads.

The public interface always queries the results from the cache.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controllers, ttl) ⇒ Cache

Returns a new instance of Cache.



15
16
17
18
19
20
# File 'lib/heartcheck/caching_app/cache.rb', line 15

def initialize(controllers, ttl)
  @results = Concurrent::Map.new
  @controllers = controllers
  @ttl = ttl
  @concurrent_opts = {}
end

Instance Attribute Details

#concurrent_optsObject

Returns the value of attribute concurrent_opts.



13
14
15
# File 'lib/heartcheck/caching_app/cache.rb', line 13

def concurrent_opts
  @concurrent_opts
end

Instance Method Details

#result(controller) ⇒ String

Fetches the current result for the given controller

Parameters:

  • controller (Class)

    the controller to fetch the current result of

Returns:

  • (String)

    the result of the index action



27
28
29
# File 'lib/heartcheck/caching_app/cache.rb', line 27

def result(controller)
  @results[controller]
end

#startObject



31
32
33
# File 'lib/heartcheck/caching_app/cache.rb', line 31

def start
  schedule(@ttl, &perform_all_controllers)
end