Module: Innate::Cache::FileBased
Overview
Used by caches that serialize their contents to the filesystem.
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #cache_clear ⇒ Object
- #cache_delete(*args) ⇒ Object
- #cache_fetch(*args) ⇒ Object
- #cache_setup(*args) ⇒ Object
- #cache_store(*args) ⇒ Object
- #transaction(&block) ⇒ Object
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/innate/cache/file_based.rb', line 6 def filename @filename end |
Instance Method Details
#cache_clear ⇒ Object
18 19 20 21 22 |
# File 'lib/innate/cache/file_based.rb', line 18 def cache_clear FileUtils.mkdir_p(@dir) FileUtils.rm_f(@filename) @store = self.class::STORE.new(@filename) end |
#cache_delete(*args) ⇒ Object
32 33 34 |
# File 'lib/innate/cache/file_based.rb', line 32 def cache_delete(*args) super{|key| transaction{|store| store.delete(key) } } end |
#cache_fetch(*args) ⇒ Object
28 29 30 |
# File 'lib/innate/cache/file_based.rb', line 28 def cache_fetch(*args) super{|key| transaction{|store| store[key] } } end |
#cache_setup(*args) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/innate/cache/file_based.rb', line 8 def cache_setup(*args) @prefix = args.compact.join('-') @dir = File.join(Dir.tmpdir, self.class::DIR) FileUtils.mkdir_p(@dir) @filename = File.join(@dir, @prefix + self.class::EXT) @store = self.class::STORE.new(@filename) end |
#cache_store(*args) ⇒ Object
24 25 26 |
# File 'lib/innate/cache/file_based.rb', line 24 def cache_store(*args) super{|key, value| transaction{|store| store[key] = value } } end |