-
Notifications
You must be signed in to change notification settings - Fork 82
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
ENH: option to set cache dir to permanent directory #106
ENH: option to set cache dir to permanent directory #106
Conversation
So let me see if I get it correctly: if the user runs this method (whatever we end up calling it), say when
I think this looks like a cool addition btw! |
""" | ||
memory.store_backend.location = path | ||
|
||
|
||
def _clear_cache(): |
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.
Could we make this method integrated with set_cache_dir
? For example but setting tmpdir
to path
automatically?
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.
Not in the current design, as we want to delete the default tmpdir at the end, but the cache dir set with set_cache_dir
does not need to be removed at the end of a session
Yes, that is correct. But note that by default, we also download all tiles into a specific directory to cache them, we only do that in a temporary directory that will be deleted afterwards.
No, that is not done, as it is specifically the purpose of using this method to not do that. If you are OK with deleting the cache at the end of the session, you can use the default temp-dir cache. A user would use this function to set a non-temp specific directory to have the cache live across several sessions.
That's the purpose of the this functionality, so the same cache can be re-used for a next session. But, the user will still need to call
I am not sure this is worth it, as there is already a cache by default (just one that does not live across sessions) |
The name I would vote for using the cache by default to reduce server usage. Even though contextily is not the main demand on such map servers, it is always good to reduce traffic. |
To be clear: you mean "use the persistent cache by default" (the default is already to cache within a session)? So that would mean to no create a temporary directory (which is destroyed afterwards), but to create somewhere in user data a contextily directory to cache? The problems that arise from this are things like: when to invalidate the cache? |
Yes
You are right, there are some open questions in that case. A compromise could be to promote the new function in the documentations of contextily and geopandas and let the user decided. |
Reading the discussion above again, I think this is actually more or less ready. I think there are two questions:
The first we need to decide upon of course, but the second could also be done as a follow-up (it would be an addition, but not changing any behaviour otherwise). |
Closes https://github.com/darribas/contextily/issues/46
cc @uvchik
For now, just added a function that the user can call as (and didn't add it in other places, like add_basemap):
I used
set_cache_dir
, but @uvchik made the suggestion to call ituse_cache
:(note that this "every time one wants to plot is not "for every
add_basemap()
call", you only need to do it once in your python session (eg put it at the beginning of your script or notebook), but it is true that you still need to do it every time once per session, it's not a permanent setting that survives across python sessions. Souse_cache
might then indeed be better, no strong feeling here)Since by default it is not called, I think it is fine to have the
path
a required argument without default (as user will only call this function if they want to set a specific cache directory, by default, a temporary directory is created by contextily which is destroyed at the end of the python session).