Class: Fluent::Plugin::RedisEnrichmentFilter::Cache::FullCache
- Defined in:
- lib/fluent/plugin/filter_redis_enrichment.rb
Instance Attribute Summary
Attributes inherited from NoCache
Instance Method Summary collapse
- #clean ⇒ Object
- #get(key) ⇒ Object
-
#initialize(*args, **kwargs) ⇒ FullCache
constructor
A new instance of FullCache.
- #initialize_cache ⇒ Object
- #reload ⇒ Object
- #timer(interval, &block) ⇒ Object
Constructor Details
#initialize(*args, **kwargs) ⇒ FullCache
Returns a new instance of FullCache.
223 224 225 226 227 |
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 223 def initialize(*args, **kwargs) super initialize_cache end |
Instance Method Details
#clean ⇒ Object
261 262 263 |
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 261 def clean @timer.exit if @timer end |
#get(key) ⇒ Object
244 245 246 |
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 244 def get(key) @cache_mutex.synchronize { @cache[key] } end |
#initialize_cache ⇒ Object
229 230 231 232 233 234 235 |
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 229 def initialize_cache @cache = {} @cache_mutex = Mutex.new reload @timer = timer(@ttl, &method(:reload)) end |
#reload ⇒ Object
237 238 239 240 241 242 |
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 237 def reload log.debug 'filter_redis_enrichment: full cache reload' if log new_cache_content = @redis.get_all @cache_mutex.synchronize { @cache.replace(new_cache_content) } log.debug 'filter_redis_enrichment: full cache reloaded' if log end |
#timer(interval, &block) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 248 def timer(interval, &block) Thread.new do loop do begin sleep interval block.call rescue StandardError => e log.warn(e) if log end end end end |