diff --git a/fsspec/implementations/cached.py b/fsspec/implementations/cached.py index 2d670522d..707e684a0 100644 --- a/fsspec/implementations/cached.py +++ b/fsspec/implementations/cached.py @@ -651,7 +651,8 @@ def cat( def _open(self, path, mode="rb", **kwargs): path = self._strip_protocol(path) if "r" not in mode: - fn = self._make_local_details(path) + hash = self._mapper(path) + fn = os.path.join(self.storage[-1], hash) user_specified_kwargs = { k: v for k, v in kwargs.items() diff --git a/fsspec/implementations/tests/test_cached.py b/fsspec/implementations/tests/test_cached.py index 091e6caf5..aa1ac2223 100644 --- a/fsspec/implementations/tests/test_cached.py +++ b/fsspec/implementations/tests/test_cached.py @@ -1313,3 +1313,17 @@ def patched_put(*args, **kwargs): assert m.cat("myfile") == b"1" assert m.cat("otherfile") == b"2" assert called[0] == 1 # copy was done in one go + + +def test_filecache_write(tmpdir, m): + fs = fsspec.filesystem( + "filecache", target_protocol="memory", cache_storage=str(tmpdir) + ) + fn = "sample_file_in_mem.txt" + data = "hello world from memory" + with fs.open(fn, "w") as f: + assert not m.exists(fn) + f.write(data) + + assert m.cat(fn) == data.encode() + assert fs.cat(fn) == data.encode()