summaryrefslogtreecommitdiff
path: root/lib/dataset_cache.rb
blob: 3f55167ec762d7fcaad15f50c4157bedefece1ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

module Lib
  
  module DatasetCache
    
    @@cache={}
      
    def self.disable()
      @@cache=nil
    end

    # same as OpenTox::Dataset.find with caching function
    # rational: datasets are reused in crossvalidation very often, cache to save computational effort
    # PENDING: may cause memory issues, test with huge datasets 
    def self.find(dataset_uri, subjectid=nil)
      return nil if (dataset_uri==nil)
      d = @@cache[dataset_uri.to_s+"_"+subjectid.to_s] if @@cache
      if d==nil
        LOGGER.debug "loading dataset #{dataset_uri}"
        d = OpenTox::Dataset.find(dataset_uri, subjectid)
        @@cache[dataset_uri.to_s+"_"+subjectid.to_s] = d if @@cache
      end
      d
    end
    
  end
  
end