Class: CacheTree::Manager
- Inherits:
-
Object
- Object
- CacheTree::Manager
- Includes:
- Singleton
- Defined in:
- lib/cache_tree.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
Instance Method Summary collapse
- #exists? ⇒ Boolean
- #expire! ⇒ Object
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
- #read ⇒ Object
- #save(data) ⇒ Object
- #use(cache_link) ⇒ Object
Constructor Details
#initialize ⇒ Manager
Returns a new instance of Manager.
15 16 17 18 |
# File 'lib/cache_tree.rb', line 15 def initialize @current_link = nil @configuration = { :perform_caching => true } end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
13 14 15 |
# File 'lib/cache_tree.rb', line 13 def configuration @configuration end |
Instance Method Details
#exists? ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/cache_tree.rb', line 24 def exists? return false unless @configuration[:perform_caching] btree_key_files = @current_link.map(:up) { |node| node.btree_key } return false unless btree_key_files.all? { |btree_key| File.exists?(btree_key) } @current_link.map(:up) { |node| node.load_btree_key } File.exists?(@current_link.cache_file) end |
#expire! ⇒ Object
32 33 34 |
# File 'lib/cache_tree.rb', line 32 def expire! @current_link.expire end |
#read ⇒ Object
36 37 38 39 |
# File 'lib/cache_tree.rb', line 36 def read @current_link.map(:up) { |node| node.load_btree_key } File.read(@current_link.cache_file) end |
#save(data) ⇒ Object
41 42 43 44 45 |
# File 'lib/cache_tree.rb', line 41 def save(data) @current_link.map(:up) { |node| node.save } FileUtils.mkdir_p(File.dirname(@current_link.cache_file)) File.open(@current_link.cache_file, 'w+') { |file| file.write data } end |
#use(cache_link) ⇒ Object
20 21 22 |
# File 'lib/cache_tree.rb', line 20 def use(cache_link) @current_link = cache_link end |