core: add base cachew directory

This commit is contained in:
Dima Gerasimov 2020-07-31 12:14:50 +01:00 committed by karlicoss
parent 10a8ebaae4
commit c54d85037c
4 changed files with 24 additions and 2 deletions

View file

@ -1,5 +1,6 @@
# TODO this probably belongs to cachew? or cachew.experimental
from contextlib import contextmanager
from pathlib import Path
def disable_cachew():
@ -25,3 +26,21 @@ def disabled_cachew():
yield
finally:
cachew.cachew = old
def cache_dir() -> Path:
'''
Base directory for cachew.
To override, add to your config file:
class config:
cache_dir = '/your/custom/cache/path'
'''
import my.config as C
common_config = getattr(C, 'common', object())
# TODO if attr is set _and_ it's none, disable cache?
cdir = getattr(common_config, 'cache_dir', None)
if cdir is None:
# TODO fallback to default cachew dir instead?
return Path('/var/tmp/cachew')
else:
return Path(cdir)