Commit b8c7815
Add S3 backend core (#338)
* Add S3 backend core (closes #41)
Implements a new cachier backend backed by AWS S3 (or any S3-compatible
service such as MinIO or localstack).
Key changes:
- src/cachier/cores/s3.py: new _S3Core implementing _BaseCore; stores one
pickled CacheEntry per key under <prefix>/<func_str>/<key>.pkl; supports
direct boto3 client, callable factory, or auto-created client via region /
endpoint_url / Config options; syncs async callers via thread delegation
from _BaseCore defaults (boto3 is sync-only).
- src/cachier/_types.py: add S3Client type alias; extend Backend literal with
"s3".
- src/cachier/core.py: wire s3_bucket, s3_prefix, s3_client, s3_client_factory,
s3_region, s3_endpoint_url, s3_config decorator parameters; import and
instantiate _S3Core.
- pyproject.toml: add "s3" pytest marker; add [project.optional-dependencies]
with per-backend extras (mongo, redis, sql, s3, all).
- tests/s3_tests/: 18 tests covering basic caching, skip/overwrite, stale_after,
next_time, allow_none, entry_size_limit, clear_cache, clear_being_calculated,
delete_stale_entries, client factory, thread safety, and error handling.
Uses moto[s3] for offline testing with no real AWS account needed.
- tests/requirements_s3.txt: boto3 + moto[s3] test deps.
- examples/s3_example.py: runnable demo for basic caching, stale_after,
client factory, and cache management.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* codex changes
* add s3 tests to the CI
* fix(async): make wrapper clear methods await-safe for coroutine-decorated functions
clear_cache/clear_being_calculated on async-decorated wrappers
previously returned None, so await func.clear_cache() raised TypeError.
Return an immediate awaitable for coroutine wrappers while preserving
existing sync usage, and add a regression test covering both sync and
awaited calls.
* fix(s3): prevent warning escalation from crashing threaded cache paths
Use a _safe_warn helper for S3 core warning paths so recoverable S3
errors still surface as warnings, but do not raise uncaught thread
exceptions under pytest -W error (fixes test_s3_core_threadsafe CI
failure).
* feat(test-local): add S3 core support and document local S3 testing in README
* test(s3): cover async aget_entry_by_key path in S3 core
* fix: satisfy ruff SIM105 in s3 warning helper
---------
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>1 parent d3b000a commit b8c7815
File tree
14 files changed
+1627
-21
lines changed- .github/workflows
- examples
- scripts
- src/cachier
- cores
- tests
- s3_tests
14 files changed
+1627
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | | - | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
580 | 580 | | |
581 | 581 | | |
582 | 582 | | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
583 | 589 | | |
584 | 590 | | |
585 | 591 | | |
| |||
631 | 637 | | |
632 | 638 | | |
633 | 639 | | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
634 | 645 | | |
635 | 646 | | |
636 | 647 | | |
| |||
655 | 666 | | |
656 | 667 | | |
657 | 668 | | |
658 | | - | |
| 669 | + | |
659 | 670 | | |
660 | 671 | | |
661 | 672 | | |
662 | 673 | | |
663 | 674 | | |
664 | 675 | | |
| 676 | + | |
665 | 677 | | |
666 | 678 | | |
667 | 679 | | |
| |||
724 | 736 | | |
725 | 737 | | |
726 | 738 | | |
727 | | - | |
| 739 | + | |
728 | 740 | | |
729 | 741 | | |
730 | 742 | | |
| |||
750 | 762 | | |
751 | 763 | | |
752 | 764 | | |
753 | | - | |
| 765 | + | |
754 | 766 | | |
755 | 767 | | |
756 | 768 | | |
757 | 769 | | |
758 | 770 | | |
759 | 771 | | |
760 | | - | |
| 772 | + | |
761 | 773 | | |
762 | 774 | | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
763 | 778 | | |
764 | | - | |
| 779 | + | |
765 | 780 | | |
766 | 781 | | |
767 | 782 | | |
| |||
772 | 787 | | |
773 | 788 | | |
774 | 789 | | |
775 | | - | |
| 790 | + | |
776 | 791 | | |
777 | 792 | | |
778 | 793 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
52 | 71 | | |
53 | 72 | | |
54 | 73 | | |
| |||
176 | 195 | | |
177 | 196 | | |
178 | 197 | | |
| 198 | + | |
179 | 199 | | |
180 | 200 | | |
181 | 201 | | |
| |||
0 commit comments