Class: Aranea::Failure::Repository
- Inherits:
-
Object
- Object
- Aranea::Failure::Repository
- Defined in:
- lib/aranea/failure_repository.rb
Overview
TODO: Actually implement Repository pattern, dependency injection and all. As is we only support sharing between multiple instances if Rails.cache exists and does
Constant Summary collapse
- KEY =
"aranea_current_failure"
Class Method Summary collapse
- .cache ⇒ Object
- .clear ⇒ Object
- .get ⇒ Object
- .memory_store ⇒ Object
- .rails_cache ⇒ Object
- .store(failure, lifespan) ⇒ Object
Class Method Details
.cache ⇒ Object
78 79 80 |
# File 'lib/aranea/failure_repository.rb', line 78 def cache @cache ||= rails_cache || memory_store end |
.clear ⇒ Object
74 75 76 |
# File 'lib/aranea/failure_repository.rb', line 74 def clear cache.delete(KEY) end |
.get ⇒ Object
70 71 72 |
# File 'lib/aranea/failure_repository.rb', line 70 def get cache.read(KEY) end |
.memory_store ⇒ Object
86 87 88 89 |
# File 'lib/aranea/failure_repository.rb', line 86 def memory_store require "active_support/cache" ActiveSupport::Cache::MemoryStore.new end |
.rails_cache ⇒ Object
82 83 84 |
# File 'lib/aranea/failure_repository.rb', line 82 def rails_cache defined?(Rails.cache) && Rails.cache end |
.store(failure, lifespan) ⇒ Object
65 66 67 68 |
# File 'lib/aranea/failure_repository.rb', line 65 def store(failure, lifespan) failure.expiration_date = Time.now + lifespan cache.write(KEY, failure, expires_in: lifespan) end |