cachify 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Pulsar Finance
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,171 @@
1
+ Metadata-Version: 2.1
2
+ Name: cachify
3
+ Version: 0.1.0
4
+ Summary: A simple cache library with sync/async support, Memory and Redis backend
5
+ Home-page: https://github.com/PulsarDataSolutions/cachify
6
+ License: MIT
7
+ Keywords: cachify,cache,caching,redis,async,decorator,memoization
8
+ Author: dynalz
9
+ Author-email: git@pulsar.finance
10
+ Requires-Python: >=3.10,<3.15
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Typing :: Typed
22
+ Requires-Dist: redis[hiredis] (>5.0.0)
23
+ Project-URL: Repository, https://github.com/PulsarDataSolutions/cachify
24
+ Description-Content-Type: text/markdown
25
+
26
+ # Python Cachify Library
27
+
28
+ A simple and robust caching library for Python functions, supporting both synchronous and asynchronous code.
29
+
30
+ ## Features
31
+
32
+ - Cache function results based on function ID and arguments
33
+ - Supports both synchronous and asynchronous functions
34
+ - Thread-safe locking to prevent duplicate cached function calls
35
+ - Configurable Time-To-Live (TTL) for cached items
36
+ - "Never Die" mode for functions that should keep cache refreshed automatically
37
+ - Skip cache functionality to force fresh function execution while updating cache
38
+ - Redis cache for distributed caching across multiple processes/machines
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ # Clone the repository
44
+ git clone https://github.com/PulsarDefi/cachify.git
45
+ cd cachify
46
+
47
+ # Install the package
48
+ poetry install
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ ### Basic Usage
54
+
55
+ ```python
56
+ from cachify import cache
57
+
58
+ # Cache function in sync functions
59
+ @cache(ttl=60) # ttl in seconds
60
+ def expensive_calculation(a, b):
61
+ # Some expensive operation
62
+ return a + b
63
+
64
+ # And async functions
65
+ @cache(ttl=3600) # ttl in seconds
66
+ async def another_calculation(url):
67
+ # Some expensive IO call
68
+ return await httpx.get(url).json()
69
+ ```
70
+
71
+ ### Redis Cache
72
+
73
+ For distributed caching across multiple processes or machines, use `rcache`:
74
+
75
+ ```python
76
+ import redis
77
+ from cachify import setup_redis_config, rcache
78
+
79
+ # Configure Redis (call once at startup)
80
+ setup_redis_config(
81
+ sync_client=redis.from_url("redis://localhost:6379/0"),
82
+ key_prefix="myapp", # default: "key_prefix", prefix searchable on redis "PREFIX:*"
83
+ lock_timeout=10, # default: 10, maximum lock lifetime in seconds
84
+ on_error="silent", # "silent" (default) or "raise" in case of redis errors
85
+ )
86
+
87
+ @rcache(ttl=300)
88
+ def get_user(user_id: int) -> dict:
89
+ return fetch_from_database(user_id)
90
+
91
+ # Async version
92
+ import redis.asyncio as aredis
93
+
94
+ setup_redis_config(async_client=aredis.from_url("redis://localhost:6379/0"))
95
+
96
+ @rcache(ttl=300)
97
+ def get_user_async(user_id: int) -> dict:
98
+ return await fetch_from_database(user_id)
99
+ ```
100
+
101
+ ### Never Die Cache
102
+
103
+ The `never_die` feature ensures that cached values never expire by automatically refreshing them in the background:
104
+
105
+ ```python
106
+ # Cache with never_die (automatic refresh)
107
+ @cache(ttl=300, never_die=True)
108
+ def critical_operation(data_id: str):
109
+ # Expensive operation that should always be available from cache
110
+ return fetch_data_from_database(data_id)
111
+ ```
112
+
113
+ **How Never Die Works:**
114
+
115
+ 1. When a function with `never_die=True` is first called, the result is cached
116
+ 2. A background thread monitors all `never_die` functions
117
+ 3. On cache expiration (TTL), the function is automatically called again
118
+ 4. The cache is updated with the new result
119
+ 5. If the refresh operation fails, the existing cached value is preserved
120
+ 6. Clients always get fast response times by reading from cache
121
+
122
+ **Benefits:**
123
+
124
+ - Cache is always "warm" and ready to serve
125
+ - No user request ever has to wait for the expensive operation
126
+ - If a dependency service from the cached function goes down temporarily, the last successful result is still available
127
+ - Perfect for critical operations where latency must be minimized
128
+
129
+ ### Skip Cache
130
+
131
+ The `skip_cache` feature allows you to bypass reading from cache while still updating it with fresh results:
132
+
133
+ ```python
134
+ @cache(ttl=300)
135
+ def get_user_data(user_id):
136
+ # Expensive operation to fetch user data
137
+ return fetch_from_database(user_id)
138
+
139
+ # Normal call - uses cache if available
140
+ user = get_user_data(123)
141
+ # Force fresh execution while updating cache
142
+ fresh_user = get_user_data(123, skip_cache=True)
143
+ # Next normal call will get the updated cached value
144
+ updated_user = get_user_data(123)
145
+ ```
146
+
147
+ **How Skip Cache Works:**
148
+
149
+ 1. When `skip_cache=True` is passed, the function bypasses reading from cache
150
+ 2. The function executes normally and returns fresh results
151
+ 3. The fresh result is stored in the cache, updating any existing cached value
152
+ 4. Subsequent calls without `skip_cache=True` will use the updated cached value
153
+ 5. The TTL timer resets from when the cache last was updated
154
+
155
+ **Benefits:**
156
+
157
+ - Force refresh of potentially stale data while keeping cache warm
158
+ - Ensuring fresh data for critical operations while maintaining cache for other calls
159
+
160
+ ## Testing
161
+
162
+ Run the test scripts
163
+
164
+ ```bash
165
+ poetry run python -m pytest
166
+ ```
167
+
168
+ ## License
169
+
170
+ MIT
171
+
@@ -0,0 +1,24 @@
1
+ cachify/__init__.py,sha256=5Q5eK7Pyty7-eSF99DBSa79FnKq27MGNiCYPkhY3uxo,553
2
+ cachify/cache.py,sha256=Y1hh3t9DlcaG8KoVi3gZHevPzZf59WPIdDb_VsooHqo,4137
3
+ cachify/config/__init__.py,sha256=xWH80AN6A2O2DlrY3ITkLYEkqnNv8WqGWhNAszVZq5w,102
4
+ cachify/features/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ cachify/features/never_die.py,sha256=A8sVAgVP-s6hlEs8FqrmHFg_-TJ8Bu8E8M_d3gwBpdg,7330
6
+ cachify/memory_cache.py,sha256=9bDgV0Lb7ZB_ieARQmiKyi0nrn7E-cqQX9lH4d9xFFk,1365
7
+ cachify/redis/__init__.py,sha256=4ZCbpo1tfU1O06pvIjerCuSR7XfopJly7mWgp9NZ_tg,429
8
+ cachify/redis/config.py,sha256=ShaNvP6-vRnxWtFk3cD6lzMcPigpCM8FnFVBv21jxk4,3673
9
+ cachify/redis/lock.py,sha256=NwrCa-z9fcXLvuaUrTsdCeNqoHIhR-Rm0J56fZ_0kT4,7513
10
+ cachify/redis_cache.py,sha256=roQ3ENdqUe6n03nX4RFB0wrOKowUEcEY96BJV48hzRQ,900
11
+ cachify/storage/__init__.py,sha256=p62r3EJPidhkHtw2OgV-gAH4U-wDtB8ZU_IbE5e3CdQ,259
12
+ cachify/storage/memory_storage.py,sha256=lwSbCYqT4NyRwgPs8TMSjHIp5aTJs6bXmQmMKFOIhVM,1533
13
+ cachify/storage/redis_storage.py,sha256=NOwWaSjca6591pMbLaHMmtelutXkAhxuWbFkoWChRnA,4905
14
+ cachify/types/__init__.py,sha256=VpDvMLFAxVo-J9MISzE-liT-wiZzo4AYHG7cQgVi-TI,2736
15
+ cachify/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ cachify/utils/arguments.py,sha256=m4TMXmZ5nC9tDyS4BBDjsW41Q7L2LOx6zEWFN70ux70,2065
17
+ cachify/utils/decorator_factory.py,sha256=5Cqz_QQDc7jVvVb_yscF41EC5o8mOda2nDeR6NvPGh8,1369
18
+ cachify/utils/functions.py,sha256=QqpdJVvmwkPtHnPhFj5xpouJL_jQ29ySOjPkgvNg-Y0,322
19
+ cachify/utils/locks.py,sha256=nvNnFuu3ooGpptH4-5tpaUU2YJmXlVqZ_GTQRWmKX7g,222
20
+ cachify-0.1.0.dist-info/entry_points.txt,sha256=a8B7GSYgDPfUClqct0o7yyBbJ61AWgSSy1idL6YZLUM,45
21
+ cachify-0.1.0.dist-info/LICENSE,sha256=nOY-lEC7Zaqf05sDxPYQ8iOGaShYMB2zf1Kr-M5hE-w,1092
22
+ cachify-0.1.0.dist-info/METADATA,sha256=pkPXhJ5vOrtH8qi56CaESR_gI4B7c_iaZbg-ZNrlNVc,5340
23
+ cachify-0.1.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
24
+ cachify-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 1.9.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ shell=scripts.shell:shell
3
+