Class: Bio::GFFbrowser::Digest::LruTracker

Inherits:
Object
  • Object
show all
Includes:
Helpers::Logger
Defined in:
lib/bio/db/gff/digest/gfflrucache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Logger

#debug, #error, #info, #log_sys_info, #warn

Constructor Details

#initializeLruTracker

Returns a new instance of LruTracker.



108
109
110
111
112
113
# File 'lib/bio/db/gff/digest/gfflrucache.rb', line 108

def initialize 
  @cache = LRUHash.new 50000
  @hits = 0
  @misses = 0
  @calls = 0
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



106
107
108
# File 'lib/bio/db/gff/digest/gfflrucache.rb', line 106

def cache
  @cache
end

#callsObject

Returns the value of attribute calls.



105
106
107
# File 'lib/bio/db/gff/digest/gfflrucache.rb', line 105

def calls
  @calls
end

#hitsObject

Returns the value of attribute hits.



105
106
107
# File 'lib/bio/db/gff/digest/gfflrucache.rb', line 105

def hits
  @hits
end

#missesObject

Returns the value of attribute misses.



105
106
107
# File 'lib/bio/db/gff/digest/gfflrucache.rb', line 105

def misses
  @misses
end

Instance Method Details

#[](name) ⇒ Object



115
116
117
118
119
120
121
122
123
124
# File 'lib/bio/db/gff/digest/gfflrucache.rb', line 115

def [](name)
  @calls += 1
  item = @cache[name]
  if @cache[name] == nil
    @misses += 1
  else
    @hits += 1
  end
  item
end

#[]=(name, item) ⇒ Object



126
127
128
# File 'lib/bio/db/gff/digest/gfflrucache.rb', line 126

def []=(name,item)
  @cache[name] = item
end

#display(msg) ⇒ Object



129
130
131
132
133
# File 'lib/bio/db/gff/digest/gfflrucache.rb', line 129

def display msg
  info "Cache calls #{msg}  = #{@calls}" 
  info "Cache hits #{msg}   = #{@hits}" 
  info "Cache misses #{msg} = #{@misses}" 
end