diff --git a/python_requests/__init__.py b/python_requests/__init__.py index eb695a1..8f5c13c 100644 --- a/python_requests/__init__.py +++ b/python_requests/__init__.py @@ -1,8 +1,14 @@ import pathlib +from .connections import Connection, SilentConnection +from .cache import clean_cache, clear_cache, set_cache_directory __name__ = "python_requests" __folder__ = str(pathlib.Path(__file__).parent) - - -CACHE_DIRECTORY = "cache" +__all__ = [ + "Connection", + "SilentConnection", + "clean_cache", + "clear_cache", + "set_cache_directory", +] diff --git a/python_requests/cache.py b/python_requests/cache.py index fb0af97..962f979 100644 --- a/python_requests/cache.py +++ b/python_requests/cache.py @@ -7,7 +7,18 @@ import pickle import sqlite3 from datetime import datetime, timedelta -from . import CACHE_DIRECTORY +from . import __name__ + +CACHE_DIRECTORY = f"/tmp/{__name__}" + + +def set_cache_directory(cache_directory: Optional[str] = None): + global CACHE_DIRECTORY + + if cache_directory is not None: + CACHE_DIRECTORY = cache_directory + + Path(CACHE_DIRECTORY).mkdir(exist_ok=True, parents=True) # SQLite database file path