Class: TaskJuggler::DataCacheEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/taskjuggler/DataCache.rb

Overview

These are the entries in the DataCache. They store a value and an access counter. The counter can be read and written externally.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(unhashedKey, value) ⇒ DataCacheEntry

Create a new DataCacheEntry for the value. We also store the unhashed key to be able to detect hash collisions. The access counter is set to 1 to increase the chance that it is not flushed immedidate.



29
30
31
32
33
# File 'lib/taskjuggler/DataCache.rb', line 29

def initialize(unhashedKey, value)
  @unhashedKey = unhashedKey
  @value = value
  @hits = 1
end

Instance Attribute Details

#hitsObject

Returns the value of attribute hits.



24
25
26
# File 'lib/taskjuggler/DataCache.rb', line 24

def hits
  @hits
end

#unhashedKeyObject (readonly)

Returns the value of attribute unhashedKey.



23
24
25
# File 'lib/taskjuggler/DataCache.rb', line 23

def unhashedKey
  @unhashedKey
end

Instance Method Details

#valueObject

Return the value and increase the access counter by 1.



36
37
38
39
40
41
42
43
# File 'lib/taskjuggler/DataCache.rb', line 36

def value
  if @hits <= 0
    @hits = 1
  else
    @hits += 1
  end
  @value
end