Module: David::MidCache

Included in:
Server
Defined in:
lib/david/server/mid_cache.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


3
4
5
# File 'lib/david/server/mid_cache.rb', line 3

def self.included(base)
  base.send(:attr_reader, :mid_cache)
end

Instance Method Details

#cacheObject


7
8
9
# File 'lib/david/server/mid_cache.rb', line 7

def cache
  @mid_cache
end

#cache_add(key, message) ⇒ Object


11
12
13
# File 'lib/david/server/mid_cache.rb', line 11

def cache_add(key, message)
  @mid_cache[key] = [message, Time.now.to_i]
end

#cache_clean!(timeout) ⇒ Object


15
16
17
18
19
# File 'lib/david/server/mid_cache.rb', line 15

def cache_clean!(timeout)
  now = Time.now.to_i
  @mid_cache.delete_if { |_, v| now - v[1] >= timeout }
  log.debug(@mid_cache.map { |k, v| v[0].to_s })
end

#cache_delete(key) ⇒ Object


21
22
23
# File 'lib/david/server/mid_cache.rb', line 21

def cache_delete(key)
  @mid_cache.delete(key)
end

#cache_get(key) ⇒ Object


25
26
27
# File 'lib/david/server/mid_cache.rb', line 25

def cache_get(key)
  @mid_cache[key]
end