Sha256: 485e7e83569530ce57d7e923073045f23f1b4bfb8f46389e8aa85e28b7b75972

Contents?: true

Size: 477 Bytes

Versions: 52

Compression:

Stored size: 477 Bytes

Contents

class ExvoAuth::Autonomous::Cache
  def initialize
    @data = {}
  end
  
  def read(key)
    o = @data[key]
    o[:value] if o && (now - o[:timestamp]) < 3600 # cache for one hour
  end
  
  def write(key, value)
    @data[key] = {
      :value     => value,
      :timestamp => now
    }
    
    value
  end
  
  def fetch(key)
    if block_given?
      read(key) || write(key, yield)
    else
      read(key)
    end
  end
  
  private
  
  def now
    Time.now
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
exvo-auth-0.10.1 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.10.0 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.9.10 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.9.9 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.9.8 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.9.7 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.9.6 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.9.5 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.9.4 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.9.3 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.9.2 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.9.0 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.8.2 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.8.0 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.7.16 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.7.15 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.7.14 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.7.13 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.7.12 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.7.11 lib/exvo_auth/autonomous/cache.rb