Class: Nucleon::Util::Cache
Constant Summary collapse
- @@cache_lock =
Mutex.new
Instance Attribute Summary
Attributes inherited from Core
Instance Method Summary collapse
-
#base_path ⇒ Object
—.
-
#clear ⇒ Object
—.
-
#delete(keys, default = nil) ⇒ Object
—.
-
#directory_name ⇒ Object
—.
-
#file ⇒ Object
—.
-
#get(keys, default = nil, format = false) ⇒ Object
—.
-
#id ⇒ Object
—.
-
#import_base(properties, options = {}) ⇒ Object
—————————————————————————– Operations.
-
#initialize(root_path, id, cache_dir = '.cache', force = true) ⇒ Cache
constructor
—————————————————————————– Constructor / Destructor.
-
#set(keys, value, delete_nil = false) ⇒ Object
—.
-
#status ⇒ Object
—————————————————————————– Property accessors / modifiers.
-
#translator ⇒ Object
—.
Methods inherited from Core
#initialized?, logger, ui, ui_group, #ui_group
Methods included from Mixin::Colors
#black, #blue, #cyan, #green, #grey, #purple, #red, #yellow
Methods inherited from Config
#[], #[]=, array, #array, #defaults, #empty?, ensure, #export, filter, #filter, #get_array, #get_hash, #has_key?, hash, #hash, #import, #init, init, init_flat, #keys, string, #string, string_map, #string_map, #symbol, symbol, #symbol_map, symbol_map, test, #test
Methods included from Mixin::ConfigOptions
#all_options, #clear_options, #contexts, #get_options, #set_options
Methods included from Mixin::ConfigCollection
#all_properties, #clear_properties, #delete_property, #get_property, #save_properties, #set_property
Constructor Details
#initialize(root_path, id, cache_dir = '.cache', force = true) ⇒ Cache
Constructor / Destructor
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/core/util/cache.rb', line 16 def initialize(root_path, id, cache_dir = '.cache', force = true) super({}, {}, force) @cache_dir = cache_dir @cache_root = File.join(root_path, cache_dir) FileUtils.mkdir_p(base_path) unless File.directory?(base_path) @cache_id = id.to_sym @cache_translator = Nucleon.type_default(:nucleon, :translator) @cache_filename = "#{id}.#{translator}" @cache_path = File.join(@cache_root, @cache_filename) load end |
Instance Method Details
#base_path ⇒ Object
40 41 42 |
# File 'lib/core/util/cache.rb', line 40 def base_path @cache_root end |
#clear ⇒ Object
99 100 101 102 103 |
# File 'lib/core/util/cache.rb', line 99 def clear result = super save if initialized? result end |
#delete(keys, default = nil) ⇒ Object
91 92 93 94 95 |
# File 'lib/core/util/cache.rb', line 91 def delete(keys, default = nil) result = super save if initialized? result end |
#directory_name ⇒ Object
46 47 48 |
# File 'lib/core/util/cache.rb', line 46 def directory_name @cache_dir end |
#file ⇒ Object
64 65 66 |
# File 'lib/core/util/cache.rb', line 64 def file @cache_path end |
#get(keys, default = nil, format = false) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/core/util/cache.rb', line 70 def get(keys, default = nil, format = false) result = super(keys, nil) if result.nil? load result = super(keys, nil) end result = filter(default, format) if result.nil? result end |
#id ⇒ Object
52 53 54 |
# File 'lib/core/util/cache.rb', line 52 def id @cache_id end |
#import_base(properties, options = {}) ⇒ Object
Operations
108 109 110 111 112 113 114 |
# File 'lib/core/util/cache.rb', line 108 def import_base(properties, = {}) config = Config.ensure() result = super save if initialized? && ! config.get(:no_save, false) result end |
#set(keys, value, delete_nil = false) ⇒ Object
83 84 85 86 87 |
# File 'lib/core/util/cache.rb', line 83 def set(keys, value, delete_nil = false) result = super save if initialized? result end |
#status ⇒ Object
Property accessors / modifiers
34 35 36 |
# File 'lib/core/util/cache.rb', line 34 def status @status end |
#translator ⇒ Object
58 59 60 |
# File 'lib/core/util/cache.rb', line 58 def translator @cache_translator end |