Class: Lux::Cache::MemoryCache
Constant Summary collapse
- @@lock =
Mutex.new
- @@ram_cache =
{}
- @@ttl_cache =
{}
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #fetch(key, ttl = nil) ⇒ Object
- #get(key) ⇒ Object
- #get_multi(*args) ⇒ Object
- #set(key, data, ttl = nil) ⇒ Object
Instance Method Details
#delete(key) ⇒ Object
27 28 29 30 31 |
# File 'lib/lux/cache/lib/memory.rb', line 27 def delete key @@lock.synchronize do @@ram_cache.delete(key) end end |
#fetch(key, ttl = nil) ⇒ Object
21 22 23 24 25 |
# File 'lib/lux/cache/lib/memory.rb', line 21 def fetch key, ttl=nil data = get key return data if data set(key, yield, ttl) end |
#get(key) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/lux/cache/lib/memory.rb', line 13 def get key if ttl_check = @@ttl_cache[key] return nil if ttl_check < Time.now.to_i end @@ram_cache[key] end |
#get_multi(*args) ⇒ Object
33 34 35 |
# File 'lib/lux/cache/lib/memory.rb', line 33 def get_multi(*args) @@ram_cache.select{ |k,v| args.index(k) } end |