Skip to content

Commit a9f70dd

Browse files
authored
Merge pull request #218 from epoch8/fix-cachefile-save
Files can be added to cache after first save
2 parents 55957db + 66c5d83 commit a9f70dd

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

fsspec/implementations/cached.py

+5
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ def save_cache(self):
135135
c["blocks"] = True
136136
else:
137137
c["blocks"] = set(c["blocks"]).union(cache[k]["blocks"])
138+
139+
# Files can be added to cache after it was written once
140+
for k, c in cache.items():
141+
if k not in cached_files:
142+
cached_files[k] = c
138143
else:
139144
cached_files = cache
140145
cache = {k: v.copy() for k, v in cached_files.items()}

fsspec/implementations/tests/test_cached.py

+19
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,22 @@ def test_takes_fs_instance():
312312
fs2 = fsspec.filesystem("filecache", target_protocol=fs)
313313

314314
assert fs2.cat(f1) == data
315+
316+
317+
def test_add_file_to_cache_after_save(local_filecache):
318+
(data, original_file, cache_location, fs) = local_filecache
319+
320+
fs.save_cache()
321+
322+
fs.cat(original_file)
323+
assert len(fs.cached_files[-1]) == 1
324+
325+
fs.save_cache()
326+
327+
fs2 = fsspec.filesystem(
328+
"filecache",
329+
target_protocol="file",
330+
cache_storage=cache_location,
331+
do_not_use_cache_for_this_instance=True, # cache is masking the issue
332+
)
333+
assert len(fs2.cached_files[-1]) == 1

0 commit comments

Comments
 (0)