Class: QaServer::PerformanceCache
- Inherits:
-
Object
- Object
- QaServer::PerformanceCache
- Defined in:
- app/cache_processors/qa_server/performance_cache.rb
Instance Method Summary collapse
- #complete_entry(id:) ⇒ Object
- #destroy(id) ⇒ Object
-
#initialize ⇒ PerformanceCache
constructor
A new instance of PerformanceCache.
- #new_entry(authority:, action:) ⇒ Object
- #update(id:, updates: {}) ⇒ Object
- #write_all ⇒ Object
Constructor Details
#initialize ⇒ PerformanceCache
Returns a new instance of PerformanceCache.
5 6 7 |
# File 'app/cache_processors/qa_server/performance_cache.rb', line 5 def initialize @cache = {} end |
Instance Method Details
#complete_entry(id:) ⇒ Object
24 25 26 27 28 |
# File 'app/cache_processors/qa_server/performance_cache.rb', line 24 def complete_entry(id:) log(id: id) QaServer.config.performance_cache_logger.debug("#{self.class}##{__method__} - id: #{id} cache memory: #{ObjectSpace.memsize_of @cache}") write_all if ObjectSpace.memsize_of(@cache) > QaServer.config.max_performance_cache_size end |
#destroy(id) ⇒ Object
30 31 32 |
# File 'app/cache_processors/qa_server/performance_cache.rb', line 30 def destroy(id) @cache.delete(id) # WARNING: doesn't change the size of the cache end |
#new_entry(authority:, action:) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'app/cache_processors/qa_server/performance_cache.rb', line 9 def new_entry(authority:, action:) entry = { dt_stamp: QaServer::TimeService.current_time, authority: , action: action } id = SecureRandom.uuid @cache[id] = entry id end |
#update(id:, updates: {}) ⇒ Object
18 19 20 21 22 |
# File 'app/cache_processors/qa_server/performance_cache.rb', line 18 def update(id:, updates: {}) return false unless id && @cache.key?(id) entry = @cache[id] @cache[id] = entry.merge(updates) end |
#write_all ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/cache_processors/qa_server/performance_cache.rb', line 34 def write_all cache_to_write = swap_cache_hash size_before = cache_to_write.size cache_to_write.each do |id, entry| next if incomplete? entry QaServer::PerformanceHistory.create(dt_stamp: entry[:dt_stamp], authority: entry[:authority], action: entry[:action], action_time_ms: entry[:action_time_ms], size_bytes: entry[:size_bytes], retrieve_time_ms: entry[:retrieve_time_ms], graph_load_time_ms: entry[:graph_load_time_ms], normalization_time_ms: entry[:normalization_time_ms]) cache_to_write.delete(id) end log_write_all("(#{self.class}##{__method__})", size_before, cache_to_write.size) cache_to_write = nil # free cache for garbage collection end |