Class: Giblish::SearchRepoCache

Inherits:
Object
  • Object
show all
Defined in:
lib/giblish/search/textsearcher.rb

Overview

Caches a number of SearchDataRepo instances in memory and returns the one corresponding to the given SearchParameters instance.

Instance Method Summary collapse

Constructor Details

#initializeSearchRepoCache

Returns a new instance of SearchRepoCache.



234
235
236
# File 'lib/giblish/search/textsearcher.rb', line 234

def initialize
  @repos = {}
end

Instance Method Details

#repo(search_parameters) ⇒ Object

search_parameters

a SearchParameters instance

returns

the SearchDataRepo corresponding to the given search parameters



241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/giblish/search/textsearcher.rb', line 241

def repo(search_parameters)
  ap = search_parameters.assets_fs_path

  # check if we shall read a new repo from disk
  if !@repos.key?(ap) || @repos[ap].is_stale
    # Uncomment for debugging...
    # puts "read from disk for ap: #{ap}.."
    # puts "is stale" if @repos.key?(ap) && @repos[ap].is_stale
    @repos[ap] = SearchDataRepo.new(ap)
  end

  @repos[ap]
end