Sha256: b08f17918d858aa95a7277cdf29f6a5626648b08dbdfe7e65a0f0d4d3596ed03

Contents?: true

Size: 718 Bytes

Versions: 24

Compression:

Stored size: 718 Bytes

Contents

class SimpleCache < Hash

  class Item
    attr_reader :expiry, :value
    def initialize(expiry, value)
      @expiry, @value = expiry, value
    end
  end

  def initialize(ttl)
    @ttl = ttl
    logger.info("  SimpleCache: will store items for #{ttl}s")
  end

  def [](key)
    item = super(key)
    if item.nil? or item.expiry <= Time.now
      logger.info("  SimpleCache: miss on #{key}")
      nil
    else
      logger.debug("  SimpleCache: hit on #{key}")
      item.value
    end
  end

  def []=(key, value)
    logger.info("  SimpleCache: store on #{key}")
    super(key, Item.new(@ttl.from_now, value))
    value
  end


  def logger
    @logger ||= RAILS_DEFAULT_LOGGER || Logger.new(STDOUT)
  end

end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
typo-3.99.0 app/models/simple_cache.rb
typo-3.99.1 app/models/simple_cache.rb
typo-3.99.3 app/models/simple_cache.rb
typo-3.99.2 app/models/simple_cache.rb
typo-3.99.4 app/models/simple_cache.rb
typo-4.0.2 app/models/simple_cache.rb
typo-4.0.1 app/models/simple_cache.rb
typo-4.0.0 app/models/simple_cache.rb
typo-4.1.1 app/models/simple_cache.rb
typo-4.0.3 app/models/simple_cache.rb
typo-5.0.2 app/models/simple_cache.rb
typo-4.1 app/models/simple_cache.rb
typo-5.0.1 app/models/simple_cache.rb
typo-5.0.3.98.1 app/models/simple_cache.rb
typo-5.0.3.98 app/models/simple_cache.rb
typo-5.0 app/models/simple_cache.rb
typo-5.1.2 app/models/simple_cache.rb
typo-5.1.1 app/models/simple_cache.rb
typo-5.1.3 app/models/simple_cache.rb
typo-5.1.98 app/models/simple_cache.rb