方法
常量
| DIR_FORMATTER | = | "%03X" |
| FILENAME_MAX_SIZE | = | 226 |
| FILEPATH_MAX_SIZE | = | 900 |
| GITKEEP_FILES | = | [".gitkeep", ".keep"].freeze |
Attributes
| [R] | cache_path |
类公共方法
new(cache_path, **options) 链接
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/cache/file_store.rb, line 20 def initialize(cache_path, **options) super(options) @cache_path = cache_path.to_s end
supports_cache_versioning?() 链接
声明缓存版本支持。
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/cache/file_store.rb, line 26 def self.supports_cache_versioning? true end
实例公共方法
cleanup(options = nil) 链接
提前遍历所有存储的键并删除已过期的键。
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/cache/file_store.rb, line 40 def cleanup(options = nil) options = merged_options(options) search_dir(cache_path) do |fname| entry = read_entry(fname, **options) delete_entry(fname, **options) if entry && entry.expired? end end
clear(options = nil) 链接
删除缓存中的所有项。在这种情况下,它会删除指定文件存储目录中的所有条目,但 .keep 或 .gitkeep 除外。在使用 FileStore 时,请小心指定配置文件中的目录,因为该目录中的所有内容都将被删除。
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/cache/file_store.rb, line 33 def clear(options = 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 end
decrement(name, amount = 1, **options) 链接
减少一个缓存的整数值。返回更新后的值。
如果键未设置,则将其设置为 -amount。
cache.decrement("foo") # => -1
要设置特定值,请调用 write
cache.write("baz", 5) cache.decrement("baz") # => 4
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/cache/file_store.rb, line 80 def decrement(name, amount = 1, **options) options = merged_options(options) key = normalize_key(name, options) instrument(:decrement, key, amount: amount) do modify_value(name, -amount, options) end end
delete_matched(matcher, options = nil) 链接
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/cache/file_store.rb, line 89 def delete_matched(matcher, options = nil) options = merged_options(options) matcher = key_matcher(matcher, options) instrument(:delete_matched, matcher.inspect) do search_dir(cache_path) do |path| key = file_path_key(path) delete_entry(path, **options) if key.match(matcher) end end end
increment(name, amount = 1, **options) 链接
增加一个缓存的整数值。返回更新后的值。
如果键未设置,则从 0 开始
cache.increment("foo") # => 1 cache.increment("bar", 100) # => 100
要设置特定值,请调用 write
cache.write("baz", 5) cache.increment("baz") # => 6
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/cache/file_store.rb, line 60 def increment(name, amount = 1, **options) options = merged_options(options) key = normalize_key(name, options) instrument(:increment, key, amount: amount) do modify_value(name, amount, options) end end