From 161ce25304bfda77b484f886ff9c0b4b23924563 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sat, 20 Mar 2021 16:38:27 +0000 Subject: [PATCH] cachew: switch to using appdirs/user cache directory instead of /tmp --- README.ipynb | 6 +++--- setup.py | 3 ++- src/cachew/__init__.py | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.ipynb b/README.ipynb index f90e3ab..e15233b 100644 --- a/README.ipynb +++ b/README.ipynb @@ -430,7 +430,7 @@ "{flink('cachew.settings')} exposes some parameters that allow you to control `cachew` behaviour:\n", "- `ENABLE`: set to `False` if you want to disable caching for without removing the decorators (useful for testing and debugging).\n", " You can also use {flink('cachew.extra.disabled_cachew')} context manager to do it temporarily.\n", - "- `DEFAULT_CACHEW_DIR`: override to set a different base directory.\n", + "- `DEFAULT_CACHEW_DIR`: override to set a different base directory. The default is the \"user cache directory\" (see [appdirs docs](https://github.com/ActiveState/appdirs#some-example-output)).\n", "- `THROW_ON_ERROR`: by default, cachew is defensive and simply attemps to cause the original function on caching issues.\n", " Set to `True` to catch errors earlier.\n", "\n", @@ -463,10 +463,10 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.2" + "version": "3.8.5" }, "name": "README.ipynb" }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/setup.py b/setup.py index e7eaad2..bf2a122 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,8 @@ description = 'Easy sqlite-backed persistent cache for dataclasses' install_requires = [ - 'sqlalchemy', + 'appdirs' , # default cache dir + 'sqlalchemy', # cache DB interaction ] diff --git a/src/cachew/__init__.py b/src/cachew/__init__.py index d387a8a..17108f8 100644 --- a/src/cachew/__init__.py +++ b/src/cachew/__init__.py @@ -32,7 +32,9 @@ import warnings -import sqlalchemy # type: ignore +import appdirs # type: ignore[import] + +import sqlalchemy # type: ignore[import] from sqlalchemy import Column, Table, event @@ -65,8 +67,7 @@ class settings: ''' ENABLE: bool = True - # switch to appdirs and using user cache dir? - DEFAULT_CACHEW_DIR: PathIsh = Path(tempfile.gettempdir()) / 'cachew' + DEFAULT_CACHEW_DIR: PathIsh = Path(appdirs.user_cache_dir('cachew')) ''' Set to true if you want to fail early. Otherwise falls back to non-cached version