cachify 0.2.0__tar.gz → 0.2.1__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.
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Pulsar Finance
3
+ Copyright (c) 2026 Pulsar Finance
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cachify
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: A simple cache library with sync/async support, Memory and Redis backend
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -28,6 +28,19 @@ Description-Content-Type: text/markdown
28
28
 
29
29
  A simple and robust caching library for Python functions, supporting both synchronous and asynchronous code.
30
30
 
31
+ ## Table of Contents
32
+
33
+ - [Features](#features)
34
+ - [Installation](#installation)
35
+ - [Usage](#usage)
36
+ - [Basic Usage](#basic-usage)
37
+ - [Redis Cache](#redis-cache)
38
+ - [Never Die Cache](#never-die-cache)
39
+ - [Skip Cache](#skip-cache)
40
+ - [Testing](#testing)
41
+ - [Contributing](#contributing)
42
+ - [License](#license)
43
+
31
44
  ## Features
32
45
 
33
46
  - Cache function results based on function ID and arguments
@@ -41,12 +54,14 @@ A simple and robust caching library for Python functions, supporting both synchr
41
54
  ## Installation
42
55
 
43
56
  ```bash
44
- # Clone the repository
45
- git clone https://github.com/PulsarDefi/cachify.git
46
- cd cachify
57
+ # Using pip
58
+ pip install cachify
59
+
60
+ # Using poetry
61
+ poetry add cachify
47
62
 
48
- # Install the package
49
- poetry install
63
+ # Using uv
64
+ uv add cachify
50
65
  ```
51
66
 
52
67
  ## Usage
@@ -57,18 +72,57 @@ poetry install
57
72
  from cachify import cache
58
73
 
59
74
  # Cache function in sync functions
60
- @cache(ttl=60) # ttl in seconds
75
+ @cache(ttl=60) # ttl in seconds
61
76
  def expensive_calculation(a, b):
62
77
  # Some expensive operation
63
78
  return a + b
64
79
 
65
80
  # And async functions
66
- @cache(ttl=3600) # ttl in seconds
81
+ @cache(ttl=3600) # ttl in seconds
67
82
  async def another_calculation(url):
68
83
  # Some expensive IO call
69
84
  return await httpx.get(url).json()
70
85
  ```
71
86
 
87
+ ### Decorator Parameters
88
+
89
+ | Parameter | Type | Default | Description |
90
+ | ---------------- | ----------------- | ------- | ---------------------------------------------------- |
91
+ | `ttl` | `int \| float` | `300` | Time to live for cached items in seconds |
92
+ | `never_die` | `bool` | `False` | If True, cache refreshes automatically in background |
93
+ | `cache_key_func` | `Callable` | `None` | Custom function to generate cache keys |
94
+ | `ignore_fields` | `tuple[str, ...]` | `()` | Function parameters to exclude from cache key |
95
+
96
+ ### Custom Cache Key Function
97
+
98
+ Use `cache_key_func` when you need custom control over how cache keys are generated:
99
+
100
+ ```python
101
+ from cachify import cache
102
+
103
+ def custom_key(args: tuple, kwargs: dict) -> str:
104
+ user_id = kwargs.get("user_id") or args[0]
105
+ return f"user:{user_id}"
106
+
107
+ @cache(ttl=60, cache_key_func=custom_key)
108
+ def get_user_profile(user_id: int):
109
+ return fetch_from_database(user_id)
110
+ ```
111
+
112
+ ### Ignore Fields
113
+
114
+ Use `ignore_fields` to exclude specific parameters from the cache key. Useful when some arguments don't affect the result:
115
+
116
+ ```python
117
+ from cachify import cache
118
+
119
+ @cache(ttl=300, ignore_fields=("logger", "request_id"))
120
+ def fetch_data(query: str, logger: Logger, request_id: str):
121
+ # Cache key only uses 'query', ignoring logger and request_id
122
+ logger.info(f"Fetching data for request {request_id}")
123
+ return database.execute(query)
124
+ ```
125
+
72
126
  ### Redis Cache
73
127
 
74
128
  For distributed caching across multiple processes or machines, use `rcache`:
@@ -80,7 +134,7 @@ from cachify import setup_redis_config, rcache
80
134
  # Configure Redis (call once at startup)
81
135
  setup_redis_config(
82
136
  sync_client=redis.from_url("redis://localhost:6379/0"),
83
- key_prefix="myapp", # default: "key_prefix", prefix searchable on redis "PREFIX:*"
137
+ key_prefix="myapp", # default: "cachify", prefix searchable on redis "PREFIX:*"
84
138
  lock_timeout=10, # default: 10, maximum lock lifetime in seconds
85
139
  on_error="silent", # "silent" (default) or "raise" in case of redis errors
86
140
  )
@@ -95,7 +149,7 @@ import redis.asyncio as aredis
95
149
  setup_redis_config(async_client=aredis.from_url("redis://localhost:6379/0"))
96
150
 
97
151
  @rcache(ttl=300)
98
- def get_user_async(user_id: int) -> dict:
152
+ async def get_user_async(user_id: int) -> dict:
99
153
  return await fetch_from_database(user_id)
100
154
  ```
101
155
 
@@ -166,7 +220,11 @@ Run the test scripts
166
220
  poetry run python -m pytest
167
221
  ```
168
222
 
223
+ ## Contributing
224
+
225
+ Contributions are welcome! Feel free to open an issue or submit a pull request.
226
+
169
227
  ## License
170
228
 
171
- MIT
229
+ This project is licensed under the MIT License - see the [LICENSE](https://github.com/PulsarDataSolutions/cachify/blob/master/LICENSE) file for details.
172
230
 
@@ -2,6 +2,19 @@
2
2
 
3
3
  A simple and robust caching library for Python functions, supporting both synchronous and asynchronous code.
4
4
 
5
+ ## Table of Contents
6
+
7
+ - [Features](#features)
8
+ - [Installation](#installation)
9
+ - [Usage](#usage)
10
+ - [Basic Usage](#basic-usage)
11
+ - [Redis Cache](#redis-cache)
12
+ - [Never Die Cache](#never-die-cache)
13
+ - [Skip Cache](#skip-cache)
14
+ - [Testing](#testing)
15
+ - [Contributing](#contributing)
16
+ - [License](#license)
17
+
5
18
  ## Features
6
19
 
7
20
  - Cache function results based on function ID and arguments
@@ -15,12 +28,14 @@ A simple and robust caching library for Python functions, supporting both synchr
15
28
  ## Installation
16
29
 
17
30
  ```bash
18
- # Clone the repository
19
- git clone https://github.com/PulsarDefi/cachify.git
20
- cd cachify
31
+ # Using pip
32
+ pip install cachify
33
+
34
+ # Using poetry
35
+ poetry add cachify
21
36
 
22
- # Install the package
23
- poetry install
37
+ # Using uv
38
+ uv add cachify
24
39
  ```
25
40
 
26
41
  ## Usage
@@ -31,18 +46,57 @@ poetry install
31
46
  from cachify import cache
32
47
 
33
48
  # Cache function in sync functions
34
- @cache(ttl=60) # ttl in seconds
49
+ @cache(ttl=60) # ttl in seconds
35
50
  def expensive_calculation(a, b):
36
51
  # Some expensive operation
37
52
  return a + b
38
53
 
39
54
  # And async functions
40
- @cache(ttl=3600) # ttl in seconds
55
+ @cache(ttl=3600) # ttl in seconds
41
56
  async def another_calculation(url):
42
57
  # Some expensive IO call
43
58
  return await httpx.get(url).json()
44
59
  ```
45
60
 
61
+ ### Decorator Parameters
62
+
63
+ | Parameter | Type | Default | Description |
64
+ | ---------------- | ----------------- | ------- | ---------------------------------------------------- |
65
+ | `ttl` | `int \| float` | `300` | Time to live for cached items in seconds |
66
+ | `never_die` | `bool` | `False` | If True, cache refreshes automatically in background |
67
+ | `cache_key_func` | `Callable` | `None` | Custom function to generate cache keys |
68
+ | `ignore_fields` | `tuple[str, ...]` | `()` | Function parameters to exclude from cache key |
69
+
70
+ ### Custom Cache Key Function
71
+
72
+ Use `cache_key_func` when you need custom control over how cache keys are generated:
73
+
74
+ ```python
75
+ from cachify import cache
76
+
77
+ def custom_key(args: tuple, kwargs: dict) -> str:
78
+ user_id = kwargs.get("user_id") or args[0]
79
+ return f"user:{user_id}"
80
+
81
+ @cache(ttl=60, cache_key_func=custom_key)
82
+ def get_user_profile(user_id: int):
83
+ return fetch_from_database(user_id)
84
+ ```
85
+
86
+ ### Ignore Fields
87
+
88
+ Use `ignore_fields` to exclude specific parameters from the cache key. Useful when some arguments don't affect the result:
89
+
90
+ ```python
91
+ from cachify import cache
92
+
93
+ @cache(ttl=300, ignore_fields=("logger", "request_id"))
94
+ def fetch_data(query: str, logger: Logger, request_id: str):
95
+ # Cache key only uses 'query', ignoring logger and request_id
96
+ logger.info(f"Fetching data for request {request_id}")
97
+ return database.execute(query)
98
+ ```
99
+
46
100
  ### Redis Cache
47
101
 
48
102
  For distributed caching across multiple processes or machines, use `rcache`:
@@ -54,7 +108,7 @@ from cachify import setup_redis_config, rcache
54
108
  # Configure Redis (call once at startup)
55
109
  setup_redis_config(
56
110
  sync_client=redis.from_url("redis://localhost:6379/0"),
57
- key_prefix="myapp", # default: "key_prefix", prefix searchable on redis "PREFIX:*"
111
+ key_prefix="myapp", # default: "cachify", prefix searchable on redis "PREFIX:*"
58
112
  lock_timeout=10, # default: 10, maximum lock lifetime in seconds
59
113
  on_error="silent", # "silent" (default) or "raise" in case of redis errors
60
114
  )
@@ -69,7 +123,7 @@ import redis.asyncio as aredis
69
123
  setup_redis_config(async_client=aredis.from_url("redis://localhost:6379/0"))
70
124
 
71
125
  @rcache(ttl=300)
72
- def get_user_async(user_id: int) -> dict:
126
+ async def get_user_async(user_id: int) -> dict:
73
127
  return await fetch_from_database(user_id)
74
128
  ```
75
129
 
@@ -140,6 +194,10 @@ Run the test scripts
140
194
  poetry run python -m pytest
141
195
  ```
142
196
 
197
+ ## Contributing
198
+
199
+ Contributions are welcome! Feel free to open an issue or submit a pull request.
200
+
143
201
  ## License
144
202
 
145
- MIT
203
+ This project is licensed under the MIT License - see the [LICENSE](https://github.com/PulsarDataSolutions/cachify/blob/master/LICENSE) file for details.
@@ -20,5 +20,4 @@ __all__ = [
20
20
  "reset_redis_config",
21
21
  "DEFAULT_KEY_PREFIX",
22
22
  "CacheKwargs",
23
- "clear_never_die_registry",
24
23
  ]
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "cachify"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  description = "A simple cache library with sync/async support, Memory and Redis backend"
5
5
  license = "MIT"
6
6
  readme = "README.md"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes