Sha256: 999974b57f3d5e1c7462b81ccb82c81f59b99f512cb02801b9109212b581c5b1

Contents?: true

Size: 428 Bytes

Versions: 14

Compression:

Stored size: 428 Bytes

Contents

module Tuktuk

class Cache

  attr_reader :store, :max_keys

  def initialize(max_keys = 1000)
    @store = {}
    @max_keys = max_keys
  end

  def get(key)
    store[key]
  end

  def set(key, value)
    return if store[key] == value
    pop if store.length > max_keys
    store[key] = value
  end

  def pop
    store.delete(store.keys.last)
  end

  def show
    store.each { |k,v| puts "#{k} -> #{v}" }; nil
  end

end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
tuktuk-0.9.0 lib/tuktuk/cache.rb
tuktuk-0.8.0 lib/tuktuk/cache.rb
tuktuk-0.7.1 lib/tuktuk/cache.rb
tuktuk-0.7.0 lib/tuktuk/cache.rb
tuktuk-0.6.5 lib/tuktuk/cache.rb
tuktuk-0.6.4 lib/tuktuk/cache.rb
tuktuk-0.6.3 lib/tuktuk/cache.rb
tuktuk-0.6.2 lib/tuktuk/cache.rb
tuktuk-0.6.1 lib/tuktuk/cache.rb
tuktuk-0.6.0 lib/tuktuk/cache.rb
tuktuk-0.5.4 lib/tuktuk/cache.rb
tuktuk-0.5.3 lib/tuktuk/cache.rb
tuktuk-0.5.2 lib/tuktuk/cache.rb
tuktuk-0.5.1 lib/tuktuk/cache.rb