Class: QaServer::CacheExpiryService

Inherits:
Object
  • Object
show all
Defined in:
app/cache_processors/qa_server/cache_expiry_service.rb

Class Method Summary collapse

Class Method Details

.cache_expired?(key:, force:, next_expiry:) ⇒ Boolean

Returns true if cache has expired or is being forced to expire.

Parameters:

  • key (String) —

    cache key

  • force (Boolean) —

    if true, forces cache to regenerate by returning true; otherwise, uses cache expiry to determine whether cache has expired

Returns:

  • (Boolean) —

    true if cache has expired or is being forced to expire



14
15
16
17
18
19
20
# File 'app/cache_processors/qa_server/cache_expiry_service.rb', line 14

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.

Returns:

  • (Float) —

    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