Class: Togul::Client
- Inherits:
-
Object
- Object
- Togul::Client
- Defined in:
- lib/togul/client.rb
Instance Method Summary collapse
-
#evaluate(key, context = {}) ⇒ Togul::EvaluateResult
Evaluate a feature flag and return the result mirroring the API response.
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
-
#invalidate_cache ⇒ Object
Clear all cached flag values.
-
#invalidate_flag(key) ⇒ Object
Clear a specific flag from cache.
-
#on_cache_invalidated(&block) ⇒ Object
Register a listener for cache invalidation events.
-
#stream ⇒ Object
Start SSE stream for real-time cache invalidation.
Constructor Details
Instance Method Details
#evaluate(key, context = {}) ⇒ Togul::EvaluateResult
Evaluate a feature flag and return the result mirroring the API response.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/togul/client.rb', line 21 def evaluate(key, context = {}) cache_key = build_cache_key(key, context) cached = @cache.get(cache_key) return cached unless cached.nil? result = fetch_evaluation(key, context) @cache.set(cache_key, result) result end |
#invalidate_cache ⇒ Object
Clear all cached flag values.
33 34 35 |
# File 'lib/togul/client.rb', line 33 def invalidate_cache @cache.flush end |
#invalidate_flag(key) ⇒ Object
Clear a specific flag from cache.
38 39 40 |
# File 'lib/togul/client.rb', line 38 def invalidate_flag(key) @cache.invalidate_flag(key) end |
#on_cache_invalidated(&block) ⇒ Object
Register a listener for cache invalidation events.
48 49 50 |
# File 'lib/togul/client.rb', line 48 def on_cache_invalidated(&block) stream.on_cache_invalidated(&block) end |
#stream ⇒ Object
Start SSE stream for real-time cache invalidation.
43 44 45 |
# File 'lib/togul/client.rb', line 43 def stream @stream_client ||= StreamClient.new(@config, @cache) end |