|
1 | 1 | # CacheToolsUtils
|
2 | 2 |
|
3 |
| -Stackable cache classes, for instance to add key prefix and stats to |
4 |
| -[cachetools](https://pypi.org/project/cachetools/) classes and use |
5 |
| -[redis](https://redis.io/) and |
6 |
| -[memcached](https://memcached.org/) as storage backends, |
7 |
| -and other cache-related utils. |
| 3 | +Stackable cache classes for sharing, encryption, statistics _and more_ |
| 4 | +on top of [cachetools](https://pypi.org/project/cachetools/), |
| 5 | +[redis](https://redis.io/) and [memcached](https://memcached.org/). |
8 | 6 |
|
9 | 7 | 
|
10 | 8 | 
|
@@ -40,9 +38,14 @@ def repeat(s: str, n: int) -> str:
|
40 | 38 | def banged(s: str, n: int) -> str:
|
41 | 39 | return repeat(s, n) + "!"
|
42 | 40 |
|
43 |
| -print(banged("aa", 3)) # add 2 cache entries |
44 |
| -print(repeat("aa", 3)) # cache hit! |
45 |
| -print(banged("aa", 3)) # cache hit! |
| 41 | +@ctu.cached(ctu.AutoPrefixedCache(cache), key=ctu.json_key) |
| 42 | +def question(s: str, n: int) -> str: |
| 43 | + return repeat(s, n) + "?" |
| 44 | + |
| 45 | +print(banged("aa", 3)) # add 2 cache entries |
| 46 | +print(question("aa", 3)) # add 1 entry, 1 hit |
| 47 | +print(repeat("aa", 3)) # cache hit! |
| 48 | +print(banged("aa", 3)) # cache hit! |
46 | 49 |
|
47 | 50 | assert cache.hits() > 0
|
48 | 51 | ```
|
|
0 commit comments