Class: Viiite::BDB::Cached
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Viiite::BDB::Cached
- Includes:
- Utils
- Defined in:
- lib/viiite/bdb/cached.rb
Defined Under Namespace
Classes: Proxy
Instance Attribute Summary collapse
-
#cache_folder ⇒ Object
readonly
Returns the value of attribute cache_folder.
-
#cache_mode ⇒ Object
readonly
Returns the value of attribute cache_mode.
Instance Method Summary collapse
- #benchmark(name) ⇒ Object
- #cached? ⇒ Boolean
- #dataset(name) ⇒ Object
-
#initialize(delegate, cache_folder, cache_mode = "w") ⇒ Cached
constructor
A new instance of Cached.
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_folder ⇒ Object (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_mode ⇒ Object (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
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 |