Class: Shugoi::ConfigCache
- Inherits:
-
Object
- Object
- Shugoi::ConfigCache
- Defined in:
- lib/shugoi/config_cache.rb
Overview
Cache mémoire de la config (whitelist + flags + skipPaths). Parité avec _configCache (render.ts) : TTL 30s + stale-refresh.
Constant Summary collapse
- TTL_MS =
30_000- STALE_MAX_MS =
600_000
Instance Method Summary collapse
- #fetch(site_key) ⇒ Object
-
#initialize(api_client) ⇒ ConfigCache
constructor
A new instance of ConfigCache.
Constructor Details
#initialize(api_client) ⇒ ConfigCache
Returns a new instance of ConfigCache.
10 11 12 13 14 15 16 17 |
# File 'lib/shugoi/config_cache.rb', line 10 def initialize(api_client) @api_client = api_client @mutex = Mutex.new @whitelist = [] @flags = {} @skip_paths = [] @fetched_at = 0 end |
Instance Method Details
#fetch(site_key) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/shugoi/config_cache.rb', line 19 def fetch(site_key) @mutex.synchronize do if @fetched_at.zero? || (Utils.now_ms - @fetched_at > STALE_MAX_MS) refresh(site_key) elsif Utils.now_ms - @fetched_at > TTL_MS Thread.new { refresh(site_key) }.abort_on_exception = false end { whitelist: @whitelist, flags: @flags, skip_paths: @skip_paths } end end |