-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CacheMapper to map from remote URL to local cached basename #1296
Conversation
Sorry for not touching this, coming to it soon |
Thanks, that would be useful. There is quite a lot of refactoring and new functionality to be added on top of this, if you think it is going in the right direction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can find nothing wrong with this at all, the one tiniest question. Can merge anyway.
Also, would be happy to remove the eq/hash stuff - does it look like it has any use? Maybe no need to do that right now.
fsspec/implementations/cached.py
Outdated
fn = os.path.join(self.storage[-1], detail["fn"]) | ||
fn = getattr(detail, "fn", "") | ||
if not fn: | ||
# fn should always be set, but be defensive here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel like if we have a condition we expect never to hit, it's probably an exception or warning. I suppose this line is not covered by tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed this to raise an exception, and added an explicit test that the exception is raised in test_cached.py::test_clear_expired
as that already contains the machinery to modify the cached metadata.
caf9986
to
4f30fdc
Compare
We can safely remove it here, we'd just need to remove 2 lines of object and hash equality tests in |
I'll merge this tomorrow morning (UK time), leaving time for any further comments before then. |
I meant only |
I see now.
|
whenever you're ready |
This is the start of work to make the caching system more configurable by splitting up different areas of responsibility of
CachingFileSystem
into separate class hierarchies that will eventually be pluggable.It starts here by separating out the mapping from remote URL to local cached basename into a new class hierarchy based on
AbstractCacheMapper
. There is no change in functionality here, the two concrete derived classes cover thesame_names=True
andsame_names=False
options ofCachingFileSystem
. It will easy in future to add newCacheMapper
classes or to modify the existing ones with extra attributes, e.g. number of directories to consider as well as the basename.Implementation details:
CacheMapper
is the best name I can think of but I am happy to change it if someone has a better idea.CachingFileSystem
no longer stores thesame_names
attribute, it is just used to create theCacheMapper
which is stored. Removal of thesame_names
attribute could be considered an API change as it was technically public.CachingFileSystem.hash_name
function even though it now defers to theCacheMapper
. This is just for backwards compatibility in case downstream libraries are using it. The localfsspec
tests all pass if it is removed.In future, to support more pluggable options we will need to be able to pass
CacheMapper
instances to theCachingFileSystem
constructor, but we will probably also have to keep thesame_names
arg for backward compatibility.(Edited: typo)