Class: BoardLinuxfr::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/board-linuxfr/cache.rb

Defined Under Namespace

Classes: Entry

Constant Summary collapse

CAPACITY =
10

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



20
21
22
23
# File 'lib/board-linuxfr/cache.rb', line 20

def initialize
  @keys = Entry.new
  @vals = Entry.new
end

Instance Method Details

#[](key) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/board-linuxfr/cache.rb', line 25

def [](key)
  n = @keys.index(key)
  unless n
    @keys.push key
    @vals.push Entry.new
    n = @keys.length - 1
  end
  @vals[n]
end