Class: QaServer::CacheExpiryService
- Inherits:
-
Object
- Object
- QaServer::CacheExpiryService
- Defined in:
- app/cache_processors/qa_server/cache_expiry_service.rb
Class Method Summary collapse
-
.cache_expired?(key:, force:, next_expiry:) ⇒ Boolean
True if cache has expired or is being forced to expire.
-
.cache_expiry ⇒ Float
Number of seconds until cache should expire.
- .end_of_hour_expiry ⇒ Object
Class Method Details
.cache_expired?(key:, force:, next_expiry:) ⇒ Boolean
Returns true if cache has expired or is being forced to expire.
19 20 21 22 23 24 25 |
# File 'app/cache_processors/qa_server/cache_expiry_service.rb', line 19 def cache_expired?(key:, force:, next_expiry:) # will return true only if the full expiry has passed or force was requested force = Rails.cache.fetch(key, expires_in: 5.minutes, race_condition_ttl: 30.seconds, force: force) { true } # reset cache so it will next expired at expected time Rails.cache.fetch(key, expires_in: next_expiry, race_condition_ttl: 30.seconds, force: true) { false } force end |
.cache_expiry ⇒ Float
Returns number of seconds until cache should expire.
7 8 9 |
# File 'app/cache_processors/qa_server/cache_expiry_service.rb', line 7 def cache_expiry cache_expires_at - QaServer::TimeService.current_time end |
.end_of_hour_expiry ⇒ Object
11 12 13 14 |
# File 'app/cache_processors/qa_server/cache_expiry_service.rb', line 11 def end_of_hour_expiry ct = QaServer::TimeService.current_time ct.end_of_hour - ct end |