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.



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

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

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



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

def cache
  @cache
end

#callsObject

Returns the value of attribute calls.



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

def calls
  @calls
end

#hitsObject

Returns the value of attribute hits.



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

def hits
  @hits
end

#missesObject

Returns the value of attribute misses.



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

def misses
  @misses
end

Instance Method Details

#[](name) ⇒ Object



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

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

#[]=(name, item) ⇒ Object



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

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

#display(msg) ⇒ Object



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

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