mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow AS::Cache::FileStore#clear without cache directory
Currently `Rails.cache.clear` raises Errno::ENOENT if it's run just after cloning a new Rails project. It should succeed without removing files or directories.
This commit is contained in:
parent
0a120a818d
commit
16d7cfb177
2 changed files with 7 additions and 0 deletions
|
@ -29,6 +29,7 @@ module ActiveSupport
|
||||||
def clear(options = nil)
|
def clear(options = nil)
|
||||||
root_dirs = Dir.entries(cache_path).reject {|f| (EXCLUDED_DIRS + [".gitkeep"]).include?(f)}
|
root_dirs = Dir.entries(cache_path).reject {|f| (EXCLUDED_DIRS + [".gitkeep"]).include?(f)}
|
||||||
FileUtils.rm_r(root_dirs.collect{|f| File.join(cache_path, f)})
|
FileUtils.rm_r(root_dirs.collect{|f| File.join(cache_path, f)})
|
||||||
|
rescue Errno::ENOENT
|
||||||
end
|
end
|
||||||
|
|
||||||
# Preemptively iterates through all stored keys and removes the ones which have expired.
|
# Preemptively iterates through all stored keys and removes the ones which have expired.
|
||||||
|
|
|
@ -684,6 +684,7 @@ class FileStoreTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
FileUtils.rm_r(cache_dir)
|
FileUtils.rm_r(cache_dir)
|
||||||
|
rescue Errno::ENOENT
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_dir
|
def cache_dir
|
||||||
|
@ -703,6 +704,11 @@ class FileStoreTest < ActiveSupport::TestCase
|
||||||
assert File.exist?(filepath)
|
assert File.exist?(filepath)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_clear_without_cache_dir
|
||||||
|
FileUtils.rm_r(cache_dir)
|
||||||
|
@cache.clear
|
||||||
|
end
|
||||||
|
|
||||||
def test_long_keys
|
def test_long_keys
|
||||||
@cache.write("a"*10000, 1)
|
@cache.write("a"*10000, 1)
|
||||||
assert_equal 1, @cache.read("a"*10000)
|
assert_equal 1, @cache.read("a"*10000)
|
||||||
|
|
Loading…
Reference in a new issue