fastapi-cachex 0.2.8__tar.gz → 0.2.10__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.
Files changed (32) hide show
  1. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/PKG-INFO +6 -6
  2. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/README.md +4 -4
  3. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/cache.py +2 -2
  4. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/dependencies.py +1 -1
  5. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/proxy.py +4 -9
  6. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/routes.py +2 -2
  7. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/session/__init__.py +2 -0
  8. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/session/middleware.py +3 -2
  9. fastapi_cachex-0.2.10/fastapi_cachex/session/proxy.py +9 -0
  10. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/state/manager.py +1 -1
  11. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/pyproject.toml +1 -1
  12. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/__init__.py +0 -0
  13. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/backends/__init__.py +0 -0
  14. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/backends/base.py +0 -0
  15. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/backends/config.py +0 -0
  16. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/backends/memcached.py +0 -0
  17. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/backends/memory.py +0 -0
  18. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/backends/redis.py +0 -0
  19. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/directives.py +0 -0
  20. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/exceptions.py +0 -0
  21. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/py.typed +0 -0
  22. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/session/config.py +0 -0
  23. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/session/dependencies.py +0 -0
  24. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/session/exceptions.py +0 -0
  25. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/session/manager.py +0 -0
  26. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/session/models.py +0 -0
  27. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/session/security.py +0 -0
  28. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/session/token_serializers.py +0 -0
  29. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/state/__init__.py +0 -0
  30. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/state/exceptions.py +0 -0
  31. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/state/models.py +0 -0
  32. {fastapi_cachex-0.2.8 → fastapi_cachex-0.2.10}/fastapi_cachex/types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastapi-cachex
3
- Version: 0.2.8
3
+ Version: 0.2.10
4
4
  Summary: A caching library for FastAPI with support for Cache-Control, ETag, and multiple backends.
5
5
  Keywords: fastapi,cache,etag,cache-control,redis,memcached,in-memory
6
6
  Author: allen0099
@@ -27,8 +27,8 @@ Requires-Dist: redis[hiredis] ; extra == 'redis'
27
27
  Requires-Dist: orjson ; extra == 'redis'
28
28
  Requires-Python: >=3.10
29
29
  Project-URL: Homepage, https://github.com/allen0099/FastAPI-CacheX
30
- Project-URL: Issues, https://github.com/allen0099/FastAPI-CacheX/issues
31
30
  Project-URL: Repository, https://github.com/allen0099/FastAPI-CacheX.git
31
+ Project-URL: Issues, https://github.com/allen0099/FastAPI-CacheX/issues
32
32
  Provides-Extra: jwt
33
33
  Provides-Extra: memcache
34
34
  Provides-Extra: redis
@@ -186,7 +186,7 @@ from fastapi_cachex.backends import MemoryBackend
186
186
  from fastapi_cachex import BackendProxy
187
187
 
188
188
  backend = MemoryBackend()
189
- BackendProxy.set_backend(backend)
189
+ BackendProxy.set(backend)
190
190
  ```
191
191
 
192
192
  **Note**: In-memory cache is not suitable for production with multiple processes.
@@ -199,7 +199,7 @@ from fastapi_cachex.backends import MemcachedBackend
199
199
  from fastapi_cachex import BackendProxy
200
200
 
201
201
  backend = MemcachedBackend(servers=["localhost:11211"])
202
- BackendProxy.set_backend(backend)
202
+ BackendProxy.set(backend)
203
203
  ```
204
204
 
205
205
  **Limitations**:
@@ -214,7 +214,7 @@ from fastapi_cachex.backends import AsyncRedisCacheBackend
214
214
  from fastapi_cachex import BackendProxy
215
215
 
216
216
  backend = AsyncRedisCacheBackend(host="127.0.0.1", port=6379, db=0)
217
- BackendProxy.set_backend(backend)
217
+ BackendProxy.set(backend)
218
218
  ```
219
219
 
220
220
  **Features**:
@@ -232,7 +232,7 @@ backend = AsyncRedisCacheBackend(
232
232
  port=6379,
233
233
  key_prefix="myapp:cache:",
234
234
  )
235
- BackendProxy.set_backend(backend)
235
+ BackendProxy.set(backend)
236
236
  ```
237
237
 
238
238
  ## Performance Considerations
@@ -150,7 +150,7 @@ from fastapi_cachex.backends import MemoryBackend
150
150
  from fastapi_cachex import BackendProxy
151
151
 
152
152
  backend = MemoryBackend()
153
- BackendProxy.set_backend(backend)
153
+ BackendProxy.set(backend)
154
154
  ```
155
155
 
156
156
  **Note**: In-memory cache is not suitable for production with multiple processes.
@@ -163,7 +163,7 @@ from fastapi_cachex.backends import MemcachedBackend
163
163
  from fastapi_cachex import BackendProxy
164
164
 
165
165
  backend = MemcachedBackend(servers=["localhost:11211"])
166
- BackendProxy.set_backend(backend)
166
+ BackendProxy.set(backend)
167
167
  ```
168
168
 
169
169
  **Limitations**:
@@ -178,7 +178,7 @@ from fastapi_cachex.backends import AsyncRedisCacheBackend
178
178
  from fastapi_cachex import BackendProxy
179
179
 
180
180
  backend = AsyncRedisCacheBackend(host="127.0.0.1", port=6379, db=0)
181
- BackendProxy.set_backend(backend)
181
+ BackendProxy.set(backend)
182
182
  ```
183
183
 
184
184
  **Features**:
@@ -196,7 +196,7 @@ backend = AsyncRedisCacheBackend(
196
196
  port=6379,
197
197
  key_prefix="myapp:cache:",
198
198
  )
199
- BackendProxy.set_backend(backend)
199
+ BackendProxy.set(backend)
200
200
  ```
201
201
 
202
202
  ## Performance Considerations
@@ -151,11 +151,11 @@ def cache(
151
151
 
152
152
  def decorator(func: HandlerCallable) -> AsyncResponseCallable:
153
153
  try:
154
- cache_backend = BackendProxy.get_backend()
154
+ cache_backend = BackendProxy.get()
155
155
  except BackendNotFoundError:
156
156
  # Fallback to memory backend if no backend is set
157
157
  cache_backend = MemoryBackend()
158
- BackendProxy.set_backend(cache_backend)
158
+ BackendProxy.set(cache_backend)
159
159
  logger.debug("No backend configured; using MemoryBackend fallback")
160
160
 
161
161
  # Analyze the original function's signature
@@ -10,7 +10,7 @@ from .proxy import BackendProxy
10
10
 
11
11
  def get_cache_backend() -> BaseCacheBackend:
12
12
  """Dependency to get the current cache backend instance."""
13
- return BackendProxy.get_backend()
13
+ return BackendProxy.get()
14
14
 
15
15
 
16
16
  CacheBackend = Annotated[BaseCacheBackend, Depends(get_cache_backend)]
@@ -9,7 +9,6 @@ from typing import TypeVar
9
9
 
10
10
  from .backends import BaseCacheBackend
11
11
  from .exceptions import BackendNotFoundError
12
- from .session.manager import SessionManager
13
12
 
14
13
  ProxyInstance = TypeVar("ProxyInstance")
15
14
 
@@ -38,7 +37,7 @@ class ProxyBase(Generic[ProxyInstance], metaclass=ProxyMeta):
38
37
  The current instance
39
38
  """
40
39
  if cls._instance is None:
41
- msg = "Instance is not set. Please set the instance first."
40
+ msg = f"No instance set for proxy {cls.__name__}"
42
41
  raise BackendNotFoundError(msg)
43
42
  return cls._instance
44
43
 
@@ -49,7 +48,7 @@ class ProxyBase(Generic[ProxyInstance], metaclass=ProxyMeta):
49
48
  Args:
50
49
  instance: The instance to set, or None to clear
51
50
  """
52
- logger.info(
51
+ logger.debug(
53
52
  "Setting instance to: <%s>",
54
53
  instance.__class__.__name__ if instance else "None",
55
54
  )
@@ -60,7 +59,7 @@ class BackendProxy(ProxyBase[BaseCacheBackend]):
60
59
  """FastAPI CacheX Proxy for backend management."""
61
60
 
62
61
  @staticmethod
63
- def get_backend() -> BaseCacheBackend:
62
+ def get_backend() -> BaseCacheBackend: # pragma: no cover
64
63
  """Get the current backend instance.
65
64
 
66
65
  .. deprecated:: 0.3.0
@@ -78,7 +77,7 @@ class BackendProxy(ProxyBase[BaseCacheBackend]):
78
77
  return BackendProxy.get()
79
78
 
80
79
  @staticmethod
81
- def set_backend(backend: BaseCacheBackend | None) -> None:
80
+ def set_backend(backend: BaseCacheBackend | None) -> None: # pragma: no cover
82
81
  """Set the backend instance.
83
82
 
84
83
  .. deprecated:: 0.3.0
@@ -94,7 +93,3 @@ class BackendProxy(ProxyBase[BaseCacheBackend]):
94
93
  stacklevel=2,
95
94
  )
96
95
  BackendProxy.set(backend)
97
-
98
-
99
- class SessionManagerProxy(ProxyBase[SessionManager]):
100
- """FastAPI CacheX Proxy for session manager management."""
@@ -266,7 +266,7 @@ def add_routes(
266
266
  CacheHitsResponse containing cache hit records and statistics
267
267
  """
268
268
  try:
269
- backend: BaseCacheBackend = BackendProxy.get_backend()
269
+ backend: BaseCacheBackend = BackendProxy.get()
270
270
  except BackendNotFoundError:
271
271
  return CacheHitsResponse(
272
272
  cached_hits=[],
@@ -294,7 +294,7 @@ def add_routes(
294
294
  CachedRecordsResponse containing cached records and statistics
295
295
  """
296
296
  try:
297
- backend: BaseCacheBackend = BackendProxy.get_backend()
297
+ backend: BaseCacheBackend = BackendProxy.get()
298
298
  except BackendNotFoundError:
299
299
  return CachedRecordsResponse(
300
300
  cached_records=[],
@@ -9,11 +9,13 @@ from .manager import SessionManager
9
9
  from .middleware import SessionMiddleware
10
10
  from .models import Session
11
11
  from .models import SessionUser
12
+ from .proxy import SessionManagerProxy
12
13
 
13
14
  __all__ = [
14
15
  "Session",
15
16
  "SessionConfig",
16
17
  "SessionManager",
18
+ "SessionManagerProxy",
17
19
  "SessionMiddleware",
18
20
  "SessionUser",
19
21
  "get_optional_session",
@@ -12,6 +12,7 @@ from starlette.types import ASGIApp
12
12
  from .config import SessionConfig
13
13
  from .exceptions import SessionError
14
14
  from .manager import SessionManager
15
+ from .proxy import SessionManagerProxy
15
16
 
16
17
  if TYPE_CHECKING:
17
18
  from .models import Session
@@ -25,7 +26,7 @@ class SessionMiddleware(BaseHTTPMiddleware):
25
26
  def __init__(
26
27
  self,
27
28
  app: ASGIApp,
28
- session_manager: SessionManager,
29
+ session_manager: SessionManager | None = None,
29
30
  config: SessionConfig | None = None,
30
31
  ) -> None:
31
32
  """Initialize session middleware.
@@ -36,7 +37,7 @@ class SessionMiddleware(BaseHTTPMiddleware):
36
37
  config: Session configuration
37
38
  """
38
39
  super().__init__(app)
39
- self.session_manager = session_manager
40
+ self.session_manager = session_manager or SessionManagerProxy.get()
40
41
 
41
42
  if config is None:
42
43
  config = self.session_manager.config
@@ -0,0 +1,9 @@
1
+ """FastAPI CacheX Proxy for session manager management."""
2
+
3
+ from fastapi_cachex.proxy import ProxyBase
4
+
5
+ from .manager import SessionManager
6
+
7
+
8
+ class SessionManagerProxy(ProxyBase[SessionManager]):
9
+ """FastAPI CacheX Proxy for session manager management."""
@@ -35,7 +35,7 @@ class StateManager:
35
35
  key_prefix: Prefix for state keys in cache backend
36
36
  default_ttl: Default time-to-live in seconds for state
37
37
  """
38
- self.backend = BackendProxy.get_backend()
38
+ self.backend = BackendProxy.get()
39
39
  self.key_prefix = key_prefix
40
40
  self.default_ttl = default_ttl
41
41
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fastapi-cachex"
3
- version = "0.2.8"
3
+ version = "0.2.10"
4
4
  description = "A caching library for FastAPI with support for Cache-Control, ETag, and multiple backends."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"