Class: Fluent::HttpRecordModifier::Cache
- Inherits:
-
Object
- Object
- Fluent::HttpRecordModifier::Cache
- Defined in:
- lib/fluent/plugin/filter_http_record_modifier.rb
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize(cache, expire) ⇒ Cache
constructor
A new instance of Cache.
- #set(key, value) ⇒ Object
Constructor Details
#initialize(cache, expire) ⇒ Cache
Returns a new instance of Cache.
237 238 239 240 241 |
# File 'lib/fluent/plugin/filter_http_record_modifier.rb', line 237 def initialize(cache, expire) @data = {} @cache = cache @expire = expire end |
Instance Method Details
#get(key) ⇒ Object
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/fluent/plugin/filter_http_record_modifier.rb', line 243 def get(key) unless @data.has_key?(key) and @cache return nil end if Time.now.to_i > @data[key]['time'] + @expire @data.delete(key) return nil end return @data[key]['value'] end |
#set(key, value) ⇒ Object
254 255 256 257 258 259 260 261 |
# File 'lib/fluent/plugin/filter_http_record_modifier.rb', line 254 def set(key, value) if @cache @data[key] = { 'time' => Time.now.to_i, 'value' => value } end end |