From 39f75a21d0630db4ea7713df14c5af73d412acbb Mon Sep 17 00:00:00 2001 From: Umar Butler Date: Mon, 6 May 2024 21:03:02 +1000 Subject: [PATCH] Releasing v0.4.0. --- CHANGELOG.md | 7 +++++++ README.md | 47 ++++++++++++++++++++++++++++++++++++++++++----- pyproject.toml | 2 +- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65a8e2d..2b5746d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ## Changelog 🔄 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.4.0] - 2024-05-06 +## Added +- Added support for the caching of both synchronous and asynchronous generator functions. +- Added `delete()`, `clear()` and `flush()` helper functions for deleting, clearing and flushing caches. + ## [0.3.2] - 2024-03-21 ### Changed - Began hashing the names of caches with `XXH3` to ensure caches may be assigned any arbitrary name, regardless of whether it is compatible with the local file system. @@ -38,6 +43,8 @@ All notable changes to `persist-cache` will be documented here. This project adh ### Added - Added the `cache()` decorator, which locally and persistently caches functions. +[0.4.0]: https://github.com/umarbutler/persist-cache/compare/v0.3.2...v0.4.0 +[0.3.2]: https://github.com/umarbutler/persist-cache/compare/v0.3.1...v0.3.2 [0.3.1]: https://github.com/umarbutler/persist-cache/compare/v0.3.0...v0.3.1 [0.3.0]: https://github.com/umarbutler/persist-cache/compare/v0.2.0...v0.3.0 [0.2.0]: https://github.com/umarbutler/persist-cache/compare/v0.1.1...v0.2.0 diff --git a/README.md b/README.md index 8360282..10b1411 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ - **💽 Persistent**: cached returns persist across sessions and are stored locally. - **⌛ Stale-free**: cached returns may be given a shelf life, after which they will be automatically flushed out. - **🦺 Process- and thread-safe**: interprocess file locks prevent processes and threads from writing over each other. -- **⏱️ Async-compatible**: asynchronous functions can be cached with the same decorator as synchronous ones. +- **⏱️ Async-compatible**: asynchronous functions can be cached with the same decorator as synchronous ones, generators included. - **👨‍🏫 Class-compatible**: methods can be cached with the same decorator as functions (although the `self` argument is always ignored). ## Installation 🧑‍🔧 @@ -49,10 +49,17 @@ def my_other_function(): ... Once created, cached functions may be managed as follows: ```python -my_function.set_expiry(60 * 60) # Change cached returns to expire after an hour. -my_function.flush_cache() # Flush out any expired cached returns. -my_function.clear_cache() # Clear out all cached returns. -my_function.delete_cache() # Delete the cache. +# Change cached returns to expire after an hour. +my_function.set_expiry(60 * 60) + +# Flush out any expired cached returns. +my_function.flush_cache() or persist_cache.flush(my_function, 60 * 60) or persist_cache.flush('my_shared_cache', 60 * 60) + +# Clear out all cached returns. +my_function.clear_cache() or persist_cache.clear(my_function) or persist_cache.clear('my_shared_cache') + +# Delete the cache. +my_function.delete_cache() or persist_cache.delete(my_function) or persist_cache.delete('my_shared_cache') ``` ## API 🧩 @@ -83,5 +90,35 @@ After being wrapped, the cached function will have the following methods attache - `clear_cache() -> None`: Clears out all cached returns. - `delete_cache() -> None`: Deletes the cache. +### `flush()` +```python +def flush( + function_or_name: str | Callable, + expiry: int | float | timedelta, +) -> None +``` + +`flush()` flushes out any expired cached returns from a cache. + +`function_or_name` represents the function or the name of the cache to be flushed. + +### `clear()` +```python +def clear(function_or_name: str | Callable) -> None +``` + +`clear()` clears out all cached returns from a cache. + +`function_or_name` represents the function or the name of the cache to be cleared. + +### `delete()` +```python +def delete(function_or_name: str | Callable) -> None +``` + +`delete()` deletes a cache. + +`function_or_name` represents the function or the name of the cache to be deleted. + ## Licence 📜 This library is licensed under the [MIT Licence](https://github.com/umarbutler/persist-cache/blob/main/LICENCE). diff --git a/pyproject.toml b/pyproject.toml index 5e5d8a8..106df35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "persist-cache" -version = "0.3.2" +version = "0.4.0" authors = [ {name="Umar Butler", email="umar@umar.au"}, ]