diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ffd190a..850573f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,16 +29,16 @@ jobs: python -m pip install pytest python -m pip install pytest-cov - - name: Install local-cache + - name: Install persist-cache run: | python -m pip install . - name: Test with pytest run: | - pytest --cov=local_cache --cov-report=xml + pytest --cov=persist_cache --cov-report=xml - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4.0.1 with: token: ${{ secrets.CODECOV_TOKEN }} - slug: umarbutler/local-cache \ No newline at end of file + slug: umarbutler/persist-cache \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 45d7313..ca246ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ ## Changelog 🔄 -All notable changes to `local-cache` will be documented here. This project adheres to [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +All notable changes to `persist-cache` will be documented here. This project adheres to [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [0.1.0] - 2024-03-12 ### Added - Added the `cache()` decorator, which locally and persistently caches functions. -[0.1.0]: https://github.com/umarbutler/local-cache/releases/tag/v0.1.0 \ No newline at end of file +[0.1.0]: https://github.com/umarbutler/persist-cache/releases/tag/v0.1.0 \ No newline at end of file diff --git a/README.md b/README.md index 79cdd28..a4d97de 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# local-cache - +# persist-cache + -`local-cache` is an *easy-to-use* Python library for lightning-fast persistent function caching. It is capable of caching both synchronous and asynchronous functions as well as methods, and is also process-safe and thread-safe. +`persist-cache` is an *easy-to-use* Python library for lightning-fast persistent function caching. It is capable of caching both synchronous and asynchronous functions as well as methods, and is also process-safe and thread-safe. ## Features 🎯 -- **⚡ Lightning-fast**: `local-cache` can cache a function call in 400 nanoseconds and return it back in a single millisecond. +- **⚡ Lightning-fast**: `persist-cache` can cache a function call in 400 nanoseconds and return it back in a single millisecond. - **💽 Persistent**: cached returns persist across sessions and are stored locally. - **⌛ Stale-free**: cached returns may be given shelf lives, after which they will be automatically flushed out. - **🦺 Process- and thread-safe**: interprocess file locks prevent processes and threads from writing over each other. @@ -12,15 +12,15 @@ - **👨‍🏫 Class-compatible**: methods can be cached with the same decorator as functions (although the `self` argument will always be ignored). ## Installation 📦 -`local-cache` may be installed with `pip`: +`persist-cache` may be installed with `pip`: ```bash -pip install local-cache +pip install persist-cache ``` ## Usage 👩‍💻 -The code snippet below demonstrates how both synchronous and asynchronous functions as well as methods can be cached with `local-cache`: +The code snippet below demonstrates how both synchronous and asynchronous functions as well as methods can be cached with `persist-cache`: ```python -from local_cache import cache +from persist_cache import cache @cache def my_function(): ... @@ -68,7 +68,7 @@ The function to be cached must accept and return [dillable](https://dill.readthe `name` represents the name of the cache (or, if `cache()` is being called as an argument-less decorator (ie, as `@cache` instead of `@cache(...)`), the function to be cached). It defaults to the hash of the qualified name of the function. If `dir` is set, `name` will be ignored. -`dir` represents the directory in which the cache should be stored. It defaults to a subdirectory bearing the name of the cache in a parent folder called '.local_cache' in the current working directory. +`dir` represents the directory in which the cache should be stored. It defaults to a subdirectory bearing the name of the cache in a parent folder called '.persist_cache' in the current working directory. `expiry` represents how long, in seconds or as a `timedelta`, function calls should persist in the cache. It defaults to `None`. @@ -81,4 +81,4 @@ After being wrapped, the cached function will have the following methods attache - `delete_cache() -> None`: Deletes the cache. ## License 📜 -This library is licensed under the [MIT License](https://github.com/umarbutler/local-cache/blob/main/LICENCE). \ No newline at end of file +This library is licensed under the [MIT License](https://github.com/umarbutler/persist-cache/blob/main/LICENCE). \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index df1c8aa..c90e2b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -name = "local-cache" +name = "persist-cache" version = "0.1.0" authors = [ {name="Umar Butler", email="umar@umar.au"}, @@ -57,7 +57,7 @@ dependencies = [ ] [project.urls] -Homepage = "https://github.com/umarbutler/local-cache" -Documentation = "https://github.com/umarbutler/local-cache/blob/main/README.md" -Issues = "https://github.com/umarbutler/local-cache/issues" -Source = "https://github.com/umarbutler/local-cache" \ No newline at end of file +Homepage = "https://github.com/umarbutler/persist-cache" +Documentation = "https://github.com/umarbutler/persist-cache/blob/main/README.md" +Issues = "https://github.com/umarbutler/persist-cache/issues" +Source = "https://github.com/umarbutler/persist-cache" \ No newline at end of file diff --git a/src/local_cache/__init__.py b/src/persist_cache/__init__.py similarity index 72% rename from src/local_cache/__init__.py rename to src/persist_cache/__init__.py index 66634b1..bd084b3 100644 --- a/src/local_cache/__init__.py +++ b/src/persist_cache/__init__.py @@ -1,3 +1,3 @@ """An easy-to-use Python library for lightning-fast persistent function caching.""" -from .local_cache import cache \ No newline at end of file +from .persist_cache import cache \ No newline at end of file diff --git a/src/local_cache/caching.py b/src/persist_cache/caching.py similarity index 100% rename from src/local_cache/caching.py rename to src/persist_cache/caching.py diff --git a/src/local_cache/helpers.py b/src/persist_cache/helpers.py similarity index 100% rename from src/local_cache/helpers.py rename to src/persist_cache/helpers.py diff --git a/src/local_cache/local_cache.py b/src/persist_cache/persist_cache.py similarity index 94% rename from src/local_cache/local_cache.py rename to src/persist_cache/persist_cache.py index 4e82483..9580db1 100644 --- a/src/local_cache/local_cache.py +++ b/src/persist_cache/persist_cache.py @@ -22,7 +22,7 @@ def cache( Arguments: name (`str | Callable`, optional): The name of the cache (or, if `cache()` is being called as an argument-less decorator (ie, as `@cache` instead of `@cache(...)`), the function to be cached). Defaults to the hash of the qualified name of the function. If `dir` is set, this argument will be ignored. - dir (`str`, optional): The directory in which the cache should be stored. Defaults to a subdirectory bearing the name of the cache in a parent folder called '.local_cache' in the current working directory. + dir (`str`, optional): The directory in which the cache should be stored. Defaults to a subdirectory bearing the name of the cache in a parent folder called '.persist_cache' in the current working directory. expiry (`int | float | timedelta`, optional): How long, in seconds or as a `timedelta`, function calls should persist in the cache. Defaults to `None`. @@ -36,12 +36,12 @@ def cache( def decorator(func: Callable) -> Callable: nonlocal name, dir, expiry - # If the cache directory has not been set, and the name of the cache has, set it to a subdirectory by that name in a directory called '.local_cache' in the current working directory, or, if the name of the cache has not been set, set the name of that subdirectory to the hash of the qualified name of the function. + # If the cache directory has not been set, and the name of the cache has, set it to a subdirectory by that name in a directory called '.persist_cache' in the current working directory, or, if the name of the cache has not been set, set the name of that subdirectory to the hash of the qualified name of the function. if dir is None: if name is not None: - dir = f'.local_cache/{name}' + dir = f'.persist_cache/{name}' else: - dir = f'.local_cache/{caching.hash(func.__qualname__)}' + dir = f'.persist_cache/{caching.hash(func.__qualname__)}' # Create the cache directory and any other necessary directories if it does not exist. if not os.path.exists(dir): diff --git a/src/local_cache/py.typed b/src/persist_cache/py.typed similarity index 100% rename from src/local_cache/py.typed rename to src/persist_cache/py.typed diff --git a/src/local_cache/serialization.py b/src/persist_cache/serialization.py similarity index 100% rename from src/local_cache/serialization.py rename to src/persist_cache/serialization.py diff --git a/tests/test_local_cache.py b/tests/test_local_cache.py index 9a98489..914da56 100644 --- a/tests/test_local_cache.py +++ b/tests/test_local_cache.py @@ -1,11 +1,11 @@ -"""Test local-cache.""" +"""Test persist-cache.""" import os import random import shutil import time from typing import Callable, Union -import local_cache +import persist_cache def _time_consuming_function( @@ -96,29 +96,29 @@ def _test_cached_function(cached_function: Callable, dir: str = None, expiry: in cached_function.delete_cache() assert not os.path.exists(dir) -def test_local_cache() -> None: - """Test `local_cache.local_cache()`.""" +def test_persist_cache() -> None: + """Test `persist_cache.persist_cache()`.""" # Cache and test the time-consuming function without arguments. - cached_function = local_cache.cache(_time_consuming_function) + cached_function = persist_cache.cache(_time_consuming_function) print('Testing the caching of the time-consuming function without arguments.') _test_cached_function(cached_function) # Cache and test the time-consuming function with arguments. - cached_function = local_cache.cache()(_time_consuming_function) + cached_function = persist_cache.cache()(_time_consuming_function) print('Testing the caching of the time-consuming function with arguments.') _test_cached_function(cached_function) # Cache and test the time-consuming function with a time-to-live. - cached_function = local_cache.cache(expiry=1)(_time_consuming_function) + cached_function = persist_cache.cache(expiry=1)(_time_consuming_function) print('Testing the caching of the time-consuming function with a time-to-live.') _test_cached_function(cached_function, expiry=1) # Cache and test the time-consuming function with a custom directory. - cached_function = local_cache.cache(dir='.custom_cache')(_time_consuming_function) + cached_function = persist_cache.cache(dir='.custom_cache')(_time_consuming_function) print('Testing the caching of the time-consuming function with a custom directory.') _test_cached_function(cached_function, dir='.custom_cache') # Remove cache directories. - for dir in {'.local_cache', '.custom_cache'}: + for dir in {'.persist_cache', '.custom_cache'}: shutil.rmtree(dir, ignore_errors=True) \ No newline at end of file