pico-caching 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pico_caching-0.1.0/.coveragerc +18 -0
- pico_caching-0.1.0/.github/ISSUE_TEMPLATE/bug_report.yml +24 -0
- pico_caching-0.1.0/.github/ISSUE_TEMPLATE/feature_request.yml +15 -0
- pico_caching-0.1.0/.github/PULL_REQUEST_TEMPLATE.md +13 -0
- pico_caching-0.1.0/.github/dependabot.yml +10 -0
- pico_caching-0.1.0/.github/workflows/ci.yml +69 -0
- pico_caching-0.1.0/.github/workflows/codeql.yml +21 -0
- pico_caching-0.1.0/.github/workflows/docs.yml +48 -0
- pico_caching-0.1.0/.github/workflows/publish-to-pypi.yml +24 -0
- pico_caching-0.1.0/AGENTS.md +36 -0
- pico_caching-0.1.0/CHANGELOG.md +21 -0
- pico_caching-0.1.0/CLAUDE.md +14 -0
- pico_caching-0.1.0/CODE_OF_CONDUCT.md +35 -0
- pico_caching-0.1.0/CONTRIBUTING.md +37 -0
- pico_caching-0.1.0/LICENSE +21 -0
- pico_caching-0.1.0/MANIFEST.in +5 -0
- pico_caching-0.1.0/PKG-INFO +110 -0
- pico_caching-0.1.0/README.md +55 -0
- pico_caching-0.1.0/SECURITY.md +11 -0
- pico_caching-0.1.0/docs/CHANGELOG.md +21 -0
- pico_caching-0.1.0/docs/LEARN.md +14 -0
- pico_caching-0.1.0/docs/architecture.md +37 -0
- pico_caching-0.1.0/docs/faq.md +20 -0
- pico_caching-0.1.0/docs/getting-started.md +49 -0
- pico_caching-0.1.0/docs/hooks.py +7 -0
- pico_caching-0.1.0/docs/index.md +25 -0
- pico_caching-0.1.0/docs/javascripts/extra.js +10 -0
- pico_caching-0.1.0/docs/reference/api.md +9 -0
- pico_caching-0.1.0/docs/reference/index.md +10 -0
- pico_caching-0.1.0/docs/requirements.txt +7 -0
- pico_caching-0.1.0/docs/skills.md +11 -0
- pico_caching-0.1.0/docs/stylesheets/extra.css +53 -0
- pico_caching-0.1.0/docs/troubleshooting.md +24 -0
- pico_caching-0.1.0/mkdocs.yml +123 -0
- pico_caching-0.1.0/pyproject.toml +76 -0
- pico_caching-0.1.0/setup.cfg +4 -0
- pico_caching-0.1.0/src/pico_caching/__init__.py +19 -0
- pico_caching-0.1.0/src/pico_caching/_version.py +1 -0
- pico_caching-0.1.0/src/pico_caching/backend.py +59 -0
- pico_caching-0.1.0/src/pico_caching/config.py +15 -0
- pico_caching-0.1.0/src/pico_caching/decorators.py +32 -0
- pico_caching-0.1.0/src/pico_caching/interceptor.py +51 -0
- pico_caching-0.1.0/src/pico_caching/py.typed +0 -0
- pico_caching-0.1.0/src/pico_caching.egg-info/PKG-INFO +110 -0
- pico_caching-0.1.0/src/pico_caching.egg-info/SOURCES.txt +53 -0
- pico_caching-0.1.0/src/pico_caching.egg-info/dependency_links.txt +1 -0
- pico_caching-0.1.0/src/pico_caching.egg-info/entry_points.txt +2 -0
- pico_caching-0.1.0/src/pico_caching.egg-info/requires.txt +7 -0
- pico_caching-0.1.0/src/pico_caching.egg-info/scm_file_list.json +51 -0
- pico_caching-0.1.0/src/pico_caching.egg-info/scm_version.json +8 -0
- pico_caching-0.1.0/src/pico_caching.egg-info/top_level.txt +1 -0
- pico_caching-0.1.0/tests/__init__.py +0 -0
- pico_caching-0.1.0/tests/conftest.py +17 -0
- pico_caching-0.1.0/tests/test_cache.py +76 -0
- pico_caching-0.1.0/tox.ini +19 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[run]
|
|
2
|
+
branch = True
|
|
3
|
+
source =
|
|
4
|
+
pico_caching
|
|
5
|
+
omit =
|
|
6
|
+
*/_version.py
|
|
7
|
+
|
|
8
|
+
[paths]
|
|
9
|
+
pico_caching =
|
|
10
|
+
src/pico_caching
|
|
11
|
+
.tox/*/lib/*/site-packages/pico_caching
|
|
12
|
+
.tox/*/site-packages/pico_caching
|
|
13
|
+
*/site-packages/pico_caching
|
|
14
|
+
|
|
15
|
+
[report]
|
|
16
|
+
show_missing = True
|
|
17
|
+
omit =
|
|
18
|
+
*/_version.py
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Bug Report
|
|
2
|
+
description: Report a bug
|
|
3
|
+
labels: [bug]
|
|
4
|
+
body:
|
|
5
|
+
- type: textarea
|
|
6
|
+
id: description
|
|
7
|
+
attributes: { label: Description }
|
|
8
|
+
validations: { required: true }
|
|
9
|
+
- type: textarea
|
|
10
|
+
id: steps
|
|
11
|
+
attributes: { label: Steps to Reproduce, render: python }
|
|
12
|
+
validations: { required: true }
|
|
13
|
+
- type: textarea
|
|
14
|
+
id: expected
|
|
15
|
+
attributes: { label: Expected Behavior }
|
|
16
|
+
validations: { required: true }
|
|
17
|
+
- type: input
|
|
18
|
+
id: version
|
|
19
|
+
attributes: { label: Package Version }
|
|
20
|
+
validations: { required: true }
|
|
21
|
+
- type: input
|
|
22
|
+
id: python
|
|
23
|
+
attributes: { label: Python Version }
|
|
24
|
+
validations: { required: true }
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
name: Feature Request
|
|
2
|
+
description: Suggest an improvement
|
|
3
|
+
labels: [enhancement]
|
|
4
|
+
body:
|
|
5
|
+
- type: textarea
|
|
6
|
+
id: problem
|
|
7
|
+
attributes: { label: Problem }
|
|
8
|
+
validations: { required: true }
|
|
9
|
+
- type: textarea
|
|
10
|
+
id: solution
|
|
11
|
+
attributes: { label: Proposed Solution }
|
|
12
|
+
validations: { required: true }
|
|
13
|
+
- type: textarea
|
|
14
|
+
id: alternatives
|
|
15
|
+
attributes: { label: Alternatives Considered }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
## Summary
|
|
2
|
+
|
|
3
|
+
## Changes
|
|
4
|
+
|
|
5
|
+
-
|
|
6
|
+
|
|
7
|
+
## Checklist
|
|
8
|
+
|
|
9
|
+
- [ ] Tests pass (`pytest tests/ -v`)
|
|
10
|
+
- [ ] Linting passes (`ruff check src/ tests/`)
|
|
11
|
+
- [ ] CHANGELOG.md updated (if user-facing)
|
|
12
|
+
- [ ] No new runtime dependencies
|
|
13
|
+
- [ ] Single-line commit messages
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
branches: [main]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
lint:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-python@v5
|
|
14
|
+
with:
|
|
15
|
+
python-version: "3.11"
|
|
16
|
+
- run: pip install ruff
|
|
17
|
+
- run: ruff check src/ tests/
|
|
18
|
+
- run: ruff format --check src/ tests/
|
|
19
|
+
|
|
20
|
+
tests:
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
strategy:
|
|
23
|
+
matrix:
|
|
24
|
+
python-version: ["3.11", "3.12", "3.13", "3.14"]
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v4
|
|
27
|
+
with:
|
|
28
|
+
fetch-depth: 0
|
|
29
|
+
- uses: actions/setup-python@v5
|
|
30
|
+
with:
|
|
31
|
+
python-version: ${{ matrix.python-version }}
|
|
32
|
+
- run: pip install tox
|
|
33
|
+
- name: Run tests with coverage
|
|
34
|
+
env:
|
|
35
|
+
SETUPTOOLS_SCM_PRETEND_VERSION: "0.1.0"
|
|
36
|
+
run: |
|
|
37
|
+
tox -e cov
|
|
38
|
+
mv .coverage .coverage.${{ matrix.python-version }}
|
|
39
|
+
- uses: actions/upload-artifact@v4
|
|
40
|
+
with:
|
|
41
|
+
name: coverage-${{ matrix.python-version }}
|
|
42
|
+
path: .coverage.${{ matrix.python-version }}
|
|
43
|
+
include-hidden-files: true
|
|
44
|
+
if-no-files-found: error
|
|
45
|
+
|
|
46
|
+
coverage:
|
|
47
|
+
needs: tests
|
|
48
|
+
runs-on: ubuntu-latest
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/checkout@v4
|
|
51
|
+
- uses: actions/setup-python@v5
|
|
52
|
+
with:
|
|
53
|
+
python-version: "3.12"
|
|
54
|
+
- uses: actions/download-artifact@v4
|
|
55
|
+
with:
|
|
56
|
+
path: coverage-reports
|
|
57
|
+
- name: Combine and upload
|
|
58
|
+
run: |
|
|
59
|
+
pip install coverage
|
|
60
|
+
files=$(find coverage-reports -type f -name ".coverage.*")
|
|
61
|
+
if [ -z "$files" ]; then echo "No coverage files"; exit 1; fi
|
|
62
|
+
coverage combine $files
|
|
63
|
+
coverage xml
|
|
64
|
+
- uses: codecov/codecov-action@v4
|
|
65
|
+
continue-on-error: true
|
|
66
|
+
with:
|
|
67
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
68
|
+
files: coverage.xml
|
|
69
|
+
fail_ci_if_error: false
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: CodeQL
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
branches: [main]
|
|
7
|
+
schedule:
|
|
8
|
+
- cron: "0 6 * * 1"
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
security-events: write
|
|
12
|
+
contents: read
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
analyze:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- uses: github/codeql-action/init@v3
|
|
20
|
+
with: { languages: python }
|
|
21
|
+
- uses: github/codeql-action/analyze@v3
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
name: Docs
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
paths: [docs/**, mkdocs.yml]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
paths: [docs/**, mkdocs.yml]
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: write
|
|
13
|
+
pages: write
|
|
14
|
+
id-token: write
|
|
15
|
+
|
|
16
|
+
concurrency:
|
|
17
|
+
group: pages
|
|
18
|
+
cancel-in-progress: false
|
|
19
|
+
|
|
20
|
+
jobs:
|
|
21
|
+
validate:
|
|
22
|
+
if: github.event_name == 'pull_request'
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
with: { fetch-depth: 0 }
|
|
27
|
+
- uses: actions/setup-python@v5
|
|
28
|
+
with: { python-version: "3.12" }
|
|
29
|
+
- run: pip install -r docs/requirements.txt
|
|
30
|
+
- run: mkdocs build --strict
|
|
31
|
+
|
|
32
|
+
deploy:
|
|
33
|
+
if: github.event_name != 'pull_request'
|
|
34
|
+
runs-on: ubuntu-latest
|
|
35
|
+
environment:
|
|
36
|
+
name: github-pages
|
|
37
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v4
|
|
40
|
+
with: { fetch-depth: 0 }
|
|
41
|
+
- uses: actions/setup-python@v5
|
|
42
|
+
with: { python-version: "3.12" }
|
|
43
|
+
- run: pip install -r docs/requirements.txt
|
|
44
|
+
- run: mkdocs build --strict --verbose
|
|
45
|
+
- uses: actions/upload-pages-artifact@v3
|
|
46
|
+
with: { path: site }
|
|
47
|
+
- id: deployment
|
|
48
|
+
uses: actions/deploy-pages@v4
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
|
|
6
|
+
permissions:
|
|
7
|
+
id-token: write
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
deploy:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
with: { fetch-depth: 0 }
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with: { python-version: "3.x" }
|
|
18
|
+
- run: pip install build
|
|
19
|
+
- run: python -m build
|
|
20
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
21
|
+
with:
|
|
22
|
+
skip-existing: true
|
|
23
|
+
verify-metadata: true
|
|
24
|
+
attestations: true
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# pico-caching
|
|
2
|
+
|
|
3
|
+
Declarative caching (@cacheable) for pico-ioc components with pluggable backends.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install -e ".[dev]"
|
|
9
|
+
pytest tests/ -v
|
|
10
|
+
pytest --cov=pico_caching --cov-report=term-missing tests/
|
|
11
|
+
mkdocs serve -f mkdocs.yml
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Project Structure
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
src/pico_caching/
|
|
18
|
+
__init__.py # Public API
|
|
19
|
+
decorators.py # @cacheable (policy on fn + intercepted_by)
|
|
20
|
+
interceptor.py # CacheInterceptor (get-or-compute)
|
|
21
|
+
backend.py # CacheBackend protocol + InMemoryCacheBackend (LRU + TTL)
|
|
22
|
+
config.py # CacheSettings (prefix "cache")
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Key Concepts
|
|
26
|
+
|
|
27
|
+
- Default key: module.Class.method(args;kwargs) repr; override with `key=callable`.
|
|
28
|
+
- TTL: per-decorator `ttl_seconds` overrides `cache.default_ttl_seconds`.
|
|
29
|
+
- Backend selection: first non-builtin `CacheBackend` component wins, else built-in LRU.
|
|
30
|
+
- Async caches the awaited result; `time.monotonic` for expiry; one lock, OrderedDict LRU.
|
|
31
|
+
- `cache.enabled: false` -> pass-through.
|
|
32
|
+
|
|
33
|
+
## Boundaries
|
|
34
|
+
|
|
35
|
+
- Do not modify `_version.py`
|
|
36
|
+
- Keep `backend.py` free of asyncio (backends are sync by contract)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-07-03
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `@cacheable` decorator (sync + async; the awaited result is cached).
|
|
15
|
+
- `CacheBackend` protocol; user backends replace the built-in automatically.
|
|
16
|
+
- `InMemoryCacheBackend`: thread-safe LRU with per-entry TTL.
|
|
17
|
+
- `CacheSettings` (prefix `cache`): `enabled`, `default_ttl_seconds`, `max_entries`.
|
|
18
|
+
- Auto-discovery through the `pico_boot.modules` entry point; zero-config.
|
|
19
|
+
|
|
20
|
+
[Unreleased]: https://github.com/dperezcabrera/pico-caching/compare/v0.1.0...HEAD
|
|
21
|
+
[0.1.0]: https://github.com/dperezcabrera/pico-caching/releases/tag/v0.1.0
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Read and follow ./AGENTS.md for project conventions.
|
|
2
|
+
|
|
3
|
+
## Pico Ecosystem Context
|
|
4
|
+
|
|
5
|
+
pico-caching provides `@cacheable` via pico-ioc `MethodInterceptor` with a pluggable `CacheBackend` protocol (built-in thread-safe in-memory LRU + TTL). Same decorator idiom as pico-pydantic. Auto-discovered via `pico_boot.modules` entry point. Config prefix `cache` (zero-config).
|
|
6
|
+
|
|
7
|
+
## Key Reminders
|
|
8
|
+
|
|
9
|
+
- pico-ioc dependency: `>= 2.2.0`
|
|
10
|
+
- **NEVER change `version_scheme`** in pyproject.toml. It MUST remain `"post-release"`.
|
|
11
|
+
- requires-python >= 3.11
|
|
12
|
+
- Commit messages: one line only
|
|
13
|
+
- Async methods cache the awaited result, never the coroutine
|
|
14
|
+
- A user `CacheBackend` @component replaces the built-in (selection in `CacheInterceptor.__init__`)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity
|
|
10
|
+
and orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to a positive environment:
|
|
15
|
+
|
|
16
|
+
* Using welcoming and inclusive language
|
|
17
|
+
* Being respectful of differing viewpoints and experiences
|
|
18
|
+
* Gracefully accepting constructive criticism
|
|
19
|
+
* Focusing on what is best for the community
|
|
20
|
+
|
|
21
|
+
Examples of unacceptable behavior:
|
|
22
|
+
|
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
24
|
+
* Public or private harassment
|
|
25
|
+
* Publishing others' private information without explicit permission
|
|
26
|
+
* Other conduct which could reasonably be considered inappropriate
|
|
27
|
+
|
|
28
|
+
## Enforcement
|
|
29
|
+
|
|
30
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
31
|
+
reported to the project maintainer at **dperezcabrera@gmail.com**.
|
|
32
|
+
|
|
33
|
+
## Attribution
|
|
34
|
+
|
|
35
|
+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Contributing to pico-caching
|
|
2
|
+
|
|
3
|
+
## Development setup
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
git clone https://github.com/dperezcabrera/pico-caching.git
|
|
7
|
+
cd pico-caching
|
|
8
|
+
python -m venv .venv && source .venv/bin/activate
|
|
9
|
+
pip install -e ".[dev]"
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Running tests
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pytest tests/ -v
|
|
16
|
+
pytest --cov=pico_caching --cov-report=term-missing tests/
|
|
17
|
+
tox
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Linting
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
ruff check src/ tests/
|
|
24
|
+
ruff format src/ tests/
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Code style
|
|
28
|
+
|
|
29
|
+
- Python 3.11+
|
|
30
|
+
- See AGENTS.md for conventions
|
|
31
|
+
- Single-line commit messages
|
|
32
|
+
|
|
33
|
+
## What NOT to do
|
|
34
|
+
|
|
35
|
+
- Don't modify `_version.py` (auto-generated)
|
|
36
|
+
- Don't change `version_scheme` in pyproject.toml
|
|
37
|
+
- Don't add runtime dependencies without discussion
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 David Pérez Cabrera
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pico-caching
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Declarative caching for the Pico ecosystem: @cacheable AOP with pluggable backends.
|
|
5
|
+
Author-email: David Perez Cabrera <dperezcabrera@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 David Pérez Cabrera
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/dperezcabrera/pico-caching
|
|
29
|
+
Project-URL: Documentation, https://dperezcabrera.github.io/pico-caching/
|
|
30
|
+
Project-URL: Repository, https://github.com/dperezcabrera/pico-caching
|
|
31
|
+
Project-URL: Changelog, https://github.com/dperezcabrera/pico-caching/blob/main/CHANGELOG.md
|
|
32
|
+
Project-URL: Issue Tracker, https://github.com/dperezcabrera/pico-caching/issues
|
|
33
|
+
Keywords: cache,cacheable,lru,ttl,aop,ioc,spring boot
|
|
34
|
+
Classifier: Development Status :: 4 - Beta
|
|
35
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
|
37
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
41
|
+
Classifier: Intended Audience :: Developers
|
|
42
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
43
|
+
Classifier: Operating System :: OS Independent
|
|
44
|
+
Classifier: Typing :: Typed
|
|
45
|
+
Requires-Python: >=3.11
|
|
46
|
+
Description-Content-Type: text/markdown
|
|
47
|
+
License-File: LICENSE
|
|
48
|
+
Requires-Dist: pico-ioc>=2.2.0
|
|
49
|
+
Provides-Extra: dev
|
|
50
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
51
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
52
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
53
|
+
Requires-Dist: ruff; extra == "dev"
|
|
54
|
+
Dynamic: license-file
|
|
55
|
+
|
|
56
|
+
# 📦 pico-caching
|
|
57
|
+
|
|
58
|
+
[](https://pypi.org/project/pico-caching/)
|
|
59
|
+
[](https://deepwiki.com/dperezcabrera/pico-caching)
|
|
60
|
+
[](https://opensource.org/licenses/MIT)
|
|
61
|
+

|
|
62
|
+
[](https://codecov.io/gh/dperezcabrera/pico-caching)
|
|
63
|
+
[](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-caching)
|
|
64
|
+
[](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-caching)
|
|
65
|
+
[](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-caching)
|
|
66
|
+
[](https://pypi.org/project/pico-caching/)
|
|
67
|
+
[](https://dperezcabrera.github.io/pico-caching/)
|
|
68
|
+
[](https://dperezcabrera.github.io/pico-learn/)
|
|
69
|
+
|
|
70
|
+
Declarative **method caching** for the [Pico](https://github.com/dperezcabrera/pico-ioc) ecosystem: `@cacheable` over pico-ioc method interception, pluggable backends, auto-discovered by [pico-boot](https://github.com/dperezcabrera/pico-boot). Zero-config.
|
|
71
|
+
|
|
72
|
+
## Install
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install pico-caching
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Use
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from pico_ioc import component
|
|
82
|
+
from pico_caching import cacheable
|
|
83
|
+
|
|
84
|
+
@component
|
|
85
|
+
class UserRepo:
|
|
86
|
+
@cacheable(ttl_seconds=60)
|
|
87
|
+
async def find(self, user_id: int): ...
|
|
88
|
+
|
|
89
|
+
@cacheable(key=lambda q: f"search:{q}")
|
|
90
|
+
def search(self, q: str): ...
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Sync and async (the awaited **result** is cached, never the coroutine). Default backend: thread-safe in-memory LRU with per-entry TTL (`cache.max_entries`, `cache.default_ttl_seconds`). Bring your own backend by implementing the `CacheBackend` protocol as a `@component` — it replaces the built-in automatically.
|
|
94
|
+
|
|
95
|
+
```yaml
|
|
96
|
+
# application.yaml (optional)
|
|
97
|
+
cache:
|
|
98
|
+
default_ttl_seconds: 300
|
|
99
|
+
max_entries: 1024
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Skipped for now: `@cache_evict` and a Redis backend — planned once real usage asks for them.
|
|
103
|
+
|
|
104
|
+
## Documentation
|
|
105
|
+
|
|
106
|
+
Full docs at **[dperezcabrera.github.io/pico-caching](https://dperezcabrera.github.io/pico-caching/)**.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# 📦 pico-caching
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/pico-caching/)
|
|
4
|
+
[](https://deepwiki.com/dperezcabrera/pico-caching)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+

|
|
7
|
+
[](https://codecov.io/gh/dperezcabrera/pico-caching)
|
|
8
|
+
[](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-caching)
|
|
9
|
+
[](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-caching)
|
|
10
|
+
[](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-caching)
|
|
11
|
+
[](https://pypi.org/project/pico-caching/)
|
|
12
|
+
[](https://dperezcabrera.github.io/pico-caching/)
|
|
13
|
+
[](https://dperezcabrera.github.io/pico-learn/)
|
|
14
|
+
|
|
15
|
+
Declarative **method caching** for the [Pico](https://github.com/dperezcabrera/pico-ioc) ecosystem: `@cacheable` over pico-ioc method interception, pluggable backends, auto-discovered by [pico-boot](https://github.com/dperezcabrera/pico-boot). Zero-config.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install pico-caching
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Use
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from pico_ioc import component
|
|
27
|
+
from pico_caching import cacheable
|
|
28
|
+
|
|
29
|
+
@component
|
|
30
|
+
class UserRepo:
|
|
31
|
+
@cacheable(ttl_seconds=60)
|
|
32
|
+
async def find(self, user_id: int): ...
|
|
33
|
+
|
|
34
|
+
@cacheable(key=lambda q: f"search:{q}")
|
|
35
|
+
def search(self, q: str): ...
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Sync and async (the awaited **result** is cached, never the coroutine). Default backend: thread-safe in-memory LRU with per-entry TTL (`cache.max_entries`, `cache.default_ttl_seconds`). Bring your own backend by implementing the `CacheBackend` protocol as a `@component` — it replaces the built-in automatically.
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
# application.yaml (optional)
|
|
42
|
+
cache:
|
|
43
|
+
default_ttl_seconds: 300
|
|
44
|
+
max_entries: 1024
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Skipped for now: `@cache_evict` and a Redis backend — planned once real usage asks for them.
|
|
48
|
+
|
|
49
|
+
## Documentation
|
|
50
|
+
|
|
51
|
+
Full docs at **[dperezcabrera.github.io/pico-caching](https://dperezcabrera.github.io/pico-caching/)**.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-07-03
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `@cacheable` decorator (sync + async; the awaited result is cached).
|
|
15
|
+
- `CacheBackend` protocol; user backends replace the built-in automatically.
|
|
16
|
+
- `InMemoryCacheBackend`: thread-safe LRU with per-entry TTL.
|
|
17
|
+
- `CacheSettings` (prefix `cache`): `enabled`, `default_ttl_seconds`, `max_entries`.
|
|
18
|
+
- Auto-discovery through the `pico_boot.modules` entry point; zero-config.
|
|
19
|
+
|
|
20
|
+
[Unreleased]: https://github.com/dperezcabrera/pico-caching/compare/v0.1.0...HEAD
|
|
21
|
+
[0.1.0]: https://github.com/dperezcabrera/pico-caching/releases/tag/v0.1.0
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Learning Roadmap
|
|
2
|
+
|
|
3
|
+
1. **Install** — `pip install pico-caching`
|
|
4
|
+
([Getting Started](getting-started.md)).
|
|
5
|
+
2. **First hit** — `@cacheable` on an expensive lookup; verify with a call
|
|
6
|
+
counter that the second call is free.
|
|
7
|
+
3. **Tune TTL** — per-method `ttl_seconds` vs `cache.default_ttl_seconds`.
|
|
8
|
+
4. **Custom keys** — `key=lambda user_id: f"user:{user_id}"` when reprs are
|
|
9
|
+
noisy.
|
|
10
|
+
5. **Your backend** — implement `CacheBackend` as a `@component` (Redis,
|
|
11
|
+
memcached); it replaces the built-in automatically
|
|
12
|
+
([Architecture](architecture.md)).
|
|
13
|
+
6. **Invalidate** — inject the backend; `delete`/`clear` until
|
|
14
|
+
`@cache_evict` exists.
|