Class: VirtualFS::DalliCache
- Inherits:
-
Object
- Object
- VirtualFS::DalliCache
- Defined in:
- lib/virtualfs/dalli_cache.rb
Instance Attribute Summary collapse
-
#expires_after ⇒ Object
Returns the value of attribute expires_after.
Instance Method Summary collapse
- #cache(key, &proc) ⇒ Object
-
#initialize(opts = {}) ⇒ DalliCache
constructor
A new instance of DalliCache.
Constructor Details
#initialize(opts = {}) ⇒ DalliCache
Returns a new instance of DalliCache.
7 8 9 10 11 12 13 14 |
# File 'lib/virtualfs/dalli_cache.rb', line 7 def initialize(opts={}) @expires_after = opts[:expires_after] || -1 opts[:expires_in] = [0, @expires_after].max opts[:namespace] ||= 'virtualfs' @client = Dalli::Client.new(opts[:host], opts) end |
Instance Attribute Details
#expires_after ⇒ Object
Returns the value of attribute expires_after.
5 6 7 |
# File 'lib/virtualfs/dalli_cache.rb', line 5 def expires_after @expires_after end |
Instance Method Details
#cache(key, &proc) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/virtualfs/dalli_cache.rb', line 16 def cache(key, &proc) value = @client.get(key) unless value value = yield @client.set(key, value) end value end |