A cache store implementation which stores everything on the filesystem.
FileStore implements the Strategy::LocalCache strategy which implements an in-memory cache inside of a block.
Methods
- C
- D
- I
- N
- R
- W
Constants
DIR_FORMATTER | = | "%03X" |
FILENAME_MAX_SIZE | = | 230 |
EXCLUDED_DIRS | = | ['.', '..'].freeze |
Attributes
[R] | cache_path |
Class Public methods
Instance Public methods
# File activesupport/lib/active_support/cache/file_store.rb, line 30 30: def cleanup(options = nil) 31: options = merged_options(options) 32: each_key(options) do |key| 33: entry = read_entry(key, options) 34: delete_entry(key, options) if entry && entry.expired? 35: end 36: end
# File activesupport/lib/active_support/cache/file_store.rb, line 52 52: def decrement(name, amount = 1, options = nil) 53: file_name = key_file_path(namespaced_key(name, options)) 54: lock_file(file_name) do 55: options = merged_options(options) 56: if num = read(name, options) 57: num = num.to_i - amount 58: write(name, num, options) 59: num 60: else 61: nil 62: end 63: end 64: end
# File activesupport/lib/active_support/cache/file_store.rb, line 66 66: def delete_matched(matcher, options = nil) 67: options = merged_options(options) 68: instrument(:delete_matched, matcher.inspect) do 69: matcher = key_matcher(matcher, options) 70: search_dir(cache_path) do |path| 71: key = file_path_key(path) 72: delete_entry(key, options) if key.match(matcher) 73: end 74: end 75: end
# File activesupport/lib/active_support/cache/file_store.rb, line 38 38: def increment(name, amount = 1, options = nil) 39: file_name = key_file_path(namespaced_key(name, options)) 40: lock_file(file_name) do 41: options = merged_options(options) 42: if num = read(name, options) 43: num = num.to_i + amount 44: write(name, num, options) 45: num 46: else 47: nil 48: end 49: end 50: end
Instance Protected methods
# File activesupport/lib/active_support/cache/file_store.rb, line 95 95: def delete_entry(key, options) 96: file_name = key_file_path(key) 97: if File.exist?(file_name) 98: begin 99: File.delete(file_name) 100: delete_empty_directories(File.dirname(file_name)) 101: true 102: rescue => e 103: # Just in case the error was caused by another process deleting the file first. 104: raise e if File.exist?(file_name) 105: false 106: end 107: end 108: end
# File activesupport/lib/active_support/cache/file_store.rb, line 88 88: def write_entry(key, entry, options) 89: file_name = key_file_path(key) 90: ensure_cache_path(File.dirname(file_name)) 91: File.atomic_write(file_name, cache_path) {|f| Marshal.dump(entry, f)} 92: true 93: end