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



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_expiryFloat

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

.end_of_hour_expiryObject



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