Skip to content

Commit

Permalink
Releasing v0.4.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
umarbutler committed May 6, 2024
1 parent c91acaf commit 39f75a2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
47 changes: 42 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 🧑‍🔧
Expand Down Expand Up @@ -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 🧩
Expand Down Expand Up @@ -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).
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
]
Expand Down

0 comments on commit 39f75a2

Please sign in to comment.