Class: Cache
- Inherits:
-
Object
- Object
- Cache
- Defined in:
- lib/cache.rb
Constant Summary collapse
- CACHE =
rubocop:disable Style/MutableConstant
{}
- CACHE_TIMEOUT =
300 seconds
5 * 60
- TIMEOUT_KEY =
'last_access_time'.freeze
- MUTEX =
Mutex.new
- CAPABILITIES =
Caching Keys
'capabilities'.freeze
- COMMAND_EXECUTOR_URL =
'command_executor_url'.freeze
Class Method Summary collapse
- .check_types(session_id, property) ⇒ Object
- .clear_cache! ⇒ Object
- .get_cache(session_id, property) ⇒ Object
- .set_cache(session_id, property, value) ⇒ Object
Class Method Details
.check_types(session_id, property) ⇒ Object
11 12 13 14 |
# File 'lib/cache.rb', line 11 def self.check_types(session_id, property) raise TypeError, 'Argument session_id should be string' unless session_id.is_a?(String) raise TypeError, 'Argument property should be string' unless property.is_a?(String) end |
.clear_cache! ⇒ Object
35 36 37 38 39 |
# File 'lib/cache.rb', line 35 def self.clear_cache! MUTEX.synchronize do CACHE.clear end end |
.get_cache(session_id, property) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/cache.rb', line 26 def self.get_cache(session_id, property) check_types(session_id, property) MUTEX.synchronize do cleanup_cache session = CACHE[session_id] || {} session[property] end end |
.set_cache(session_id, property, value) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/cache.rb', line 16 def self.set_cache(session_id, property, value) check_types(session_id, property) MUTEX.synchronize do session = CACHE[session_id] || {} session[TIMEOUT_KEY] = Time.now.to_f session[property] = value CACHE[session_id] = session end end |