Class: Shugoi::GuardCache
- Inherits:
-
Object
- Object
- Shugoi::GuardCache
- Defined in:
- lib/shugoi/guard_cache.rb
Overview
Cache mémoire des guards (guard-detect) fetchés depuis l'API. Parité avec _guardCaches (render.ts).
Constant Summary collapse
- TTL_MS =
300_000
Instance Method Summary collapse
- #detect ⇒ Object
- #ensure_ready(site_key, secret = nil) ⇒ Object
-
#initialize(api_client) ⇒ GuardCache
constructor
A new instance of GuardCache.
Constructor Details
#initialize(api_client) ⇒ GuardCache
Returns a new instance of GuardCache.
11 12 13 14 15 16 |
# File 'lib/shugoi/guard_cache.rb', line 11 def initialize(api_client) @api_client = api_client @detect = nil @fetched_at = 0 @mutex = Mutex.new end |
Instance Method Details
#detect ⇒ Object
18 19 20 |
# File 'lib/shugoi/guard_cache.rb', line 18 def detect @detect end |
#ensure_ready(site_key, secret = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/shugoi/guard_cache.rb', line 22 def ensure_ready(site_key, secret = nil) return if @detect && Utils.now_ms - @fetched_at < TTL_MS @mutex.synchronize do return if @detect && Utils.now_ms - @fetched_at < TTL_MS code = @api_client.fetch_guard_detect(site_key, secret) @detect = code && !code.empty? ? code : 'console.error("Shugoi guard-detect unavailable")' @fetched_at = Utils.now_ms end end |