fastapi-cachex 0.2.7__tar.gz → 0.2.8__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.7 → fastapi_cachex-0.2.8}/PKG-INFO +1 -1
  2. fastapi_cachex-0.2.8/fastapi_cachex/proxy.py +100 -0
  3. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/pyproject.toml +1 -1
  4. fastapi_cachex-0.2.7/fastapi_cachex/proxy.py +0 -43
  5. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/README.md +0 -0
  6. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/__init__.py +0 -0
  7. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/backends/__init__.py +0 -0
  8. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/backends/base.py +0 -0
  9. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/backends/config.py +0 -0
  10. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/backends/memcached.py +0 -0
  11. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/backends/memory.py +0 -0
  12. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/backends/redis.py +0 -0
  13. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/cache.py +0 -0
  14. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/dependencies.py +0 -0
  15. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/directives.py +0 -0
  16. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/exceptions.py +0 -0
  17. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/py.typed +0 -0
  18. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/routes.py +0 -0
  19. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/session/__init__.py +0 -0
  20. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/session/config.py +0 -0
  21. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/session/dependencies.py +0 -0
  22. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/session/exceptions.py +0 -0
  23. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/session/manager.py +0 -0
  24. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/session/middleware.py +0 -0
  25. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/session/models.py +0 -0
  26. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/session/security.py +0 -0
  27. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/session/token_serializers.py +0 -0
  28. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/state/__init__.py +0 -0
  29. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/state/exceptions.py +0 -0
  30. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/state/manager.py +0 -0
  31. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/fastapi_cachex/state/models.py +0 -0
  32. {fastapi_cachex-0.2.7 → fastapi_cachex-0.2.8}/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.7
3
+ Version: 0.2.8
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
@@ -0,0 +1,100 @@
1
+ """Backend proxy for managing cache backend instances."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import warnings
6
+ from logging import getLogger
7
+ from typing import Generic
8
+ from typing import TypeVar
9
+
10
+ from .backends import BaseCacheBackend
11
+ from .exceptions import BackendNotFoundError
12
+ from .session.manager import SessionManager
13
+
14
+ ProxyInstance = TypeVar("ProxyInstance")
15
+
16
+ logger = getLogger(__name__)
17
+
18
+
19
+ class ProxyMeta(type):
20
+ """Metaclass for BackendProxy to prevent instantiation."""
21
+
22
+ def __call__(cls) -> None:
23
+ """Prevent instantiation of BackendProxy."""
24
+ msg = "Proxy class cannot be instantiated. Use static methods instead."
25
+ raise TypeError(msg)
26
+
27
+
28
+ class ProxyBase(Generic[ProxyInstance], metaclass=ProxyMeta):
29
+ """Abstract base class for proxy classes."""
30
+
31
+ _instance: ProxyInstance | None = None
32
+
33
+ @classmethod
34
+ def get(cls) -> ProxyInstance:
35
+ """Get the current instance of the proxy.
36
+
37
+ Returns:
38
+ The current instance
39
+ """
40
+ if cls._instance is None:
41
+ msg = "Instance is not set. Please set the instance first."
42
+ raise BackendNotFoundError(msg)
43
+ return cls._instance
44
+
45
+ @classmethod
46
+ def set(cls, instance: ProxyInstance | None) -> None:
47
+ """Set the instance for the proxy.
48
+
49
+ Args:
50
+ instance: The instance to set, or None to clear
51
+ """
52
+ logger.info(
53
+ "Setting instance to: <%s>",
54
+ instance.__class__.__name__ if instance else "None",
55
+ )
56
+ cls._instance = instance
57
+
58
+
59
+ class BackendProxy(ProxyBase[BaseCacheBackend]):
60
+ """FastAPI CacheX Proxy for backend management."""
61
+
62
+ @staticmethod
63
+ def get_backend() -> BaseCacheBackend:
64
+ """Get the current backend instance.
65
+
66
+ .. deprecated:: 0.3.0
67
+ Use :meth:`get` instead. Will be removed in version 0.4.0.
68
+
69
+ Returns:
70
+ The current backend instance
71
+ """
72
+ warnings.warn(
73
+ "get_backend() is deprecated, use get() instead. "
74
+ "Will be removed in version 0.4.0.",
75
+ DeprecationWarning,
76
+ stacklevel=2,
77
+ )
78
+ return BackendProxy.get()
79
+
80
+ @staticmethod
81
+ def set_backend(backend: BaseCacheBackend | None) -> None:
82
+ """Set the backend instance.
83
+
84
+ .. deprecated:: 0.3.0
85
+ Use :meth:`set` instead. Will be removed in version 0.4.0.
86
+
87
+ Args:
88
+ backend: The backend instance to set, or None to clear
89
+ """
90
+ warnings.warn(
91
+ "set_backend() is deprecated, use set() instead. "
92
+ "Will be removed in version 0.4.0.",
93
+ DeprecationWarning,
94
+ stacklevel=2,
95
+ )
96
+ BackendProxy.set(backend)
97
+
98
+
99
+ class SessionManagerProxy(ProxyBase[SessionManager]):
100
+ """FastAPI CacheX Proxy for session manager management."""
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fastapi-cachex"
3
- version = "0.2.7"
3
+ version = "0.2.8"
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"
@@ -1,43 +0,0 @@
1
- """Backend proxy for managing cache backend instances."""
2
-
3
- from logging import getLogger
4
-
5
- from .backends import BaseCacheBackend
6
- from .exceptions import BackendNotFoundError
7
-
8
- _default_backend: BaseCacheBackend | None = None
9
- logger = getLogger(__name__)
10
-
11
-
12
- class BackendProxy:
13
- """FastAPI CacheX Proxy for backend management."""
14
-
15
- @staticmethod
16
- def get_backend() -> BaseCacheBackend:
17
- """Get the current cache backend instance.
18
-
19
- Returns:
20
- The current cache backend
21
-
22
- Raises:
23
- BackendNotFoundError: If no backend has been set
24
- """
25
- if _default_backend is None:
26
- msg = "Backend is not set. Please set the backend first."
27
- raise BackendNotFoundError(msg)
28
-
29
- return _default_backend
30
-
31
- @staticmethod
32
- def set_backend(backend: BaseCacheBackend | None) -> None:
33
- """Set the backend for caching.
34
-
35
- Args:
36
- backend: The backend to use for caching, or None to clear the current backend
37
- """
38
- global _default_backend
39
- logger.info(
40
- "Setting backend to: <%s>",
41
- backend.__class__.__name__ if backend else "None",
42
- )
43
- _default_backend = backend
File without changes