Class: Viiite::BDB::Cached

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Utils
Defined in:
lib/viiite/bdb/cached.rb

Defined Under Namespace

Classes: Proxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#bench_file, #replace_extension

Constructor Details

#initialize(delegate, cache_folder, cache_mode = "w") ⇒ Cached

Returns a new instance of Cached.



9
10
11
12
13
# File 'lib/viiite/bdb/cached.rb', line 9

def initialize(delegate, cache_folder, cache_mode = "w")
  super delegate
  @cache_folder = cache_folder
  @cache_mode   = cache_mode
end

Instance Attribute Details

#cache_folderObject (readonly)

Returns the value of attribute cache_folder.



6
7
8
# File 'lib/viiite/bdb/cached.rb', line 6

def cache_folder
  @cache_folder
end

#cache_modeObject (readonly)

Returns the value of attribute cache_mode.



7
8
9
# File 'lib/viiite/bdb/cached.rb', line 7

def cache_mode
  @cache_mode
end

Instance Method Details

#benchmark(name) ⇒ Object



19
20
21
22
23
# File 'lib/viiite/bdb/cached.rb', line 19

def benchmark(name)
  bench = super(name)
  cache = cache_file(name)
  Proxy.new(bench, cache, cache_mode)
end

#cached?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/viiite/bdb/cached.rb', line 15

def cached?
  true
end

#dataset(name) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/viiite/bdb/cached.rb', line 25

def dataset(name)
  if File.exists?(cache_file = cache_file(name))
    Alf::Reader.reader(cache_file, self)
  else
    benchmark(name)
  end
end