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.16.5 lib/exvo_auth/autonomous/cache.rb
exvo_auth-0.16.4 lib/exvo_auth/autonomous/cache.rb
exvo_auth-0.16.3 lib/exvo_auth/autonomous/cache.rb
exvo_auth-0.16.2 lib/exvo_auth/autonomous/cache.rb
exvo_auth-0.16.1 lib/exvo_auth/autonomous/cache.rb
exvo_auth-0.16.0 lib/exvo_auth/autonomous/cache.rb
exvo_auth-0.15.1 lib/exvo_auth/autonomous/cache.rb
exvo_auth-0.15.0 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.14.1 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.14.0 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.13.0 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.12.2 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.12.1 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.12.0 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.11.2 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.11.1 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.11.0 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.10.4 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.10.3 lib/exvo_auth/autonomous/cache.rb
exvo-auth-0.10.2 lib/exvo_auth/autonomous/cache.rb