Class: Fluent::Plugin::RedisEnrichmentFilter::Cache::FullCache

Inherits:
NoCache
  • Object
show all
Defined in:
lib/fluent/plugin/filter_redis_enrichment.rb

Instance Attribute Summary

Attributes inherited from NoCache

#log

Instance Method Summary collapse

Constructor Details

#initialize(*args, **kwargs) ⇒ FullCache

Returns a new instance of FullCache.



228
229
230
231
232
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 228

def initialize(*args, **kwargs)
  super

  initialize_cache
end

Instance Method Details

#cleanObject



266
267
268
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 266

def clean
  @timer.exit if @timer
end

#get(key) ⇒ Object



249
250
251
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 249

def get(key)
  @cache_mutex.synchronize { @cache[key] }
end

#initialize_cacheObject



234
235
236
237
238
239
240
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 234

def initialize_cache
  @cache = {}
  @cache_mutex = Mutex.new

  reload
  @timer = timer(@ttl, &method(:reload))
end

#reloadObject



242
243
244
245
246
247
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 242

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



253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 253

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