Class: Zm::Support::Cache::FileStore
- Defined in:
- lib/zm/support/cache/file_store.rb
Constant Summary collapse
- GITKEEP_FILES =
%w[.gitkeep .keep].freeze
Instance Attribute Summary collapse
-
#cache_path ⇒ Object
readonly
Returns the value of attribute cache_path.
Attributes inherited from Store
Class Method Summary collapse
Instance Method Summary collapse
- #cleanup(options = nil) ⇒ Object
- #clear(_options = nil) ⇒ Object
-
#initialize(**options) ⇒ FileStore
constructor
A new instance of FileStore.
-
#inspect ⇒ Object
:nodoc:.
Methods inherited from Store
#delete, #exist?, #fetch, #read, #write
Constructor Details
#initialize(**options) ⇒ FileStore
Returns a new instance of FileStore.
21 22 23 24 |
# File 'lib/zm/support/cache/file_store.rb', line 21 def initialize(**) @cache_path = .delete(:cache_path).to_s super() end |
Instance Attribute Details
#cache_path ⇒ Object (readonly)
Returns the value of attribute cache_path.
17 18 19 |
# File 'lib/zm/support/cache/file_store.rb', line 17 def cache_path @cache_path end |
Class Method Details
.test_required_options(options) ⇒ Object
12 13 14 |
# File 'lib/zm/support/cache/file_store.rb', line 12 def () .key?(:cache_path) end |
Instance Method Details
#cleanup(options = nil) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/zm/support/cache/file_store.rb', line 33 def cleanup( = nil) = () search_dir(cache_path) do |fname| entry = read_entry(fname, **) delete_entry(fname, **) if entry&.expired? end end |
#clear(_options = nil) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/zm/support/cache/file_store.rb', line 26 def clear( = nil) root_dirs = (Dir.children(cache_path) - GITKEEP_FILES) FileUtils.rm_r(root_dirs.collect { |f| File.join(cache_path, f) }) rescue Errno::ENOENT, Errno::ENOTEMPTY => e @logger&.error "FileStoreError (#{e}): #{e.message}" end |
#inspect ⇒ Object
:nodoc:
41 42 43 |
# File 'lib/zm/support/cache/file_store.rb', line 41 def inspect # :nodoc: "#<#{self.class.name} cache_path=#{@cache_path}, options=#{@options.inspect}>" end |