fastapi-cachex 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.
Potentially problematic release.
This version of fastapi-cachex might be problematic. Click here for more details.
- fastapi_cachex/__init__.py +2 -0
- fastapi_cachex/backends/__init__.py +2 -0
- fastapi_cachex/backends/base.py +27 -0
- fastapi_cachex/backends/memory.py +74 -0
- fastapi_cachex/cache.py +193 -0
- fastapi_cachex/directives.py +19 -0
- fastapi_cachex/exceptions.py +14 -0
- fastapi_cachex/proxy.py +23 -0
- fastapi_cachex/types.py +19 -0
- fastapi_cachex-0.1.0.dist-info/METADATA +111 -0
- fastapi_cachex-0.1.0.dist-info/RECORD +14 -0
- fastapi_cachex-0.1.0.dist-info/WHEEL +5 -0
- fastapi_cachex-0.1.0.dist-info/licenses/LICENSE +201 -0
- fastapi_cachex-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from abc import abstractmethod
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from fastapi_cachex.types import ETagContent
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BaseCacheBackend(ABC):
|
|
9
|
+
"""Base class for all cache backends."""
|
|
10
|
+
|
|
11
|
+
@abstractmethod
|
|
12
|
+
async def get(self, key: str) -> Optional[ETagContent]:
|
|
13
|
+
"""Retrieve a cached response."""
|
|
14
|
+
|
|
15
|
+
@abstractmethod
|
|
16
|
+
async def set(
|
|
17
|
+
self, key: str, value: ETagContent, ttl: Optional[int] = None
|
|
18
|
+
) -> None:
|
|
19
|
+
"""Store a response in the cache."""
|
|
20
|
+
|
|
21
|
+
@abstractmethod
|
|
22
|
+
async def delete(self, key: str) -> None:
|
|
23
|
+
"""Remove a response from the cache."""
|
|
24
|
+
|
|
25
|
+
@abstractmethod
|
|
26
|
+
async def clear(self) -> None:
|
|
27
|
+
"""Clear all cached responses."""
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import time
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from fastapi_cachex.types import CacheItem
|
|
6
|
+
from fastapi_cachex.types import ETagContent
|
|
7
|
+
|
|
8
|
+
from .base import BaseCacheBackend
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class MemoryBackend(BaseCacheBackend):
|
|
12
|
+
"""In-memory cache backend implementation."""
|
|
13
|
+
|
|
14
|
+
def __init__(self) -> None:
|
|
15
|
+
self.cache: dict[str, CacheItem] = {}
|
|
16
|
+
self.lock = asyncio.Lock()
|
|
17
|
+
self.cleanup_interval = 60
|
|
18
|
+
self._cleanup_task: Optional[asyncio.Task] = None
|
|
19
|
+
|
|
20
|
+
def start_cleanup(self) -> None:
|
|
21
|
+
"""Start the cleanup task if it's not already running."""
|
|
22
|
+
if self._cleanup_task is None:
|
|
23
|
+
self._cleanup_task = asyncio.create_task(self._cleanup_task_impl())
|
|
24
|
+
|
|
25
|
+
def stop_cleanup(self) -> None:
|
|
26
|
+
"""Stop the cleanup task if it's running."""
|
|
27
|
+
if self._cleanup_task is not None:
|
|
28
|
+
self._cleanup_task.cancel()
|
|
29
|
+
self._cleanup_task = None
|
|
30
|
+
|
|
31
|
+
async def get(self, key: str) -> Optional[ETagContent]:
|
|
32
|
+
async with self.lock:
|
|
33
|
+
cached_item = self.cache.get(key)
|
|
34
|
+
if cached_item:
|
|
35
|
+
if cached_item.expiry is None or cached_item.expiry > time.time():
|
|
36
|
+
return cached_item.value
|
|
37
|
+
else:
|
|
38
|
+
return None
|
|
39
|
+
return None
|
|
40
|
+
|
|
41
|
+
async def set(
|
|
42
|
+
self, key: str, value: ETagContent, ttl: Optional[int] = None
|
|
43
|
+
) -> None:
|
|
44
|
+
async with self.lock:
|
|
45
|
+
expiry = time.time() + ttl if ttl is not None else None
|
|
46
|
+
self.cache[key] = CacheItem(value=value, expiry=expiry)
|
|
47
|
+
|
|
48
|
+
async def delete(self, key: str) -> None:
|
|
49
|
+
async with self.lock:
|
|
50
|
+
self.cache.pop(key, None)
|
|
51
|
+
|
|
52
|
+
async def clear(self) -> None:
|
|
53
|
+
async with self.lock:
|
|
54
|
+
self.cache.clear()
|
|
55
|
+
|
|
56
|
+
async def _cleanup_task_impl(self) -> None:
|
|
57
|
+
try:
|
|
58
|
+
while True:
|
|
59
|
+
await asyncio.sleep(self.cleanup_interval)
|
|
60
|
+
await self.cleanup() # pragma: no cover
|
|
61
|
+
except asyncio.CancelledError:
|
|
62
|
+
# Handle task cancellation gracefully
|
|
63
|
+
pass
|
|
64
|
+
|
|
65
|
+
async def cleanup(self) -> None:
|
|
66
|
+
async with self.lock:
|
|
67
|
+
now = time.time()
|
|
68
|
+
expired_keys = [
|
|
69
|
+
k
|
|
70
|
+
for k, v in self.cache.items()
|
|
71
|
+
if v.expiry is not None and v.expiry <= now
|
|
72
|
+
]
|
|
73
|
+
for key in expired_keys:
|
|
74
|
+
self.cache.pop(key, None)
|
fastapi_cachex/cache.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
import inspect
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from functools import wraps
|
|
5
|
+
from inspect import Parameter
|
|
6
|
+
from inspect import Signature
|
|
7
|
+
from typing import Any
|
|
8
|
+
from typing import Literal
|
|
9
|
+
from typing import Optional
|
|
10
|
+
|
|
11
|
+
from fastapi import Request
|
|
12
|
+
from fastapi import Response
|
|
13
|
+
from fastapi.responses import JSONResponse
|
|
14
|
+
from starlette.status import HTTP_304_NOT_MODIFIED
|
|
15
|
+
|
|
16
|
+
from fastapi_cachex.backends import MemoryBackend
|
|
17
|
+
from fastapi_cachex.directives import DirectiveType
|
|
18
|
+
from fastapi_cachex.exceptions import BackendNotFoundError
|
|
19
|
+
from fastapi_cachex.exceptions import CacheXError
|
|
20
|
+
from fastapi_cachex.exceptions import RequestNotFoundError
|
|
21
|
+
from fastapi_cachex.proxy import BackendProxy
|
|
22
|
+
from fastapi_cachex.types import ETagContent
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class CacheControl:
|
|
26
|
+
def __init__(self) -> None:
|
|
27
|
+
self.directives = []
|
|
28
|
+
|
|
29
|
+
def add(self, directive: DirectiveType, value: Optional[int] = None) -> None:
|
|
30
|
+
if value is not None:
|
|
31
|
+
self.directives.append(f"{directive.value}={value}")
|
|
32
|
+
else:
|
|
33
|
+
self.directives.append(directive.value)
|
|
34
|
+
|
|
35
|
+
def __str__(self) -> str:
|
|
36
|
+
return ", ".join(self.directives)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
async def get_response(func: Callable, *args: Any, **kwargs: Any) -> Response:
|
|
40
|
+
"""Get the response from the function."""
|
|
41
|
+
if inspect.iscoroutinefunction(func):
|
|
42
|
+
return await func(*args, **kwargs)
|
|
43
|
+
else:
|
|
44
|
+
return func(*args, **kwargs)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def cache( # noqa: C901
|
|
48
|
+
ttl: Optional[int] = None,
|
|
49
|
+
stale_ttl: Optional[int] = None,
|
|
50
|
+
stale: Literal["error", "revalidate"] | None = None,
|
|
51
|
+
no_cache: bool = False,
|
|
52
|
+
no_store: bool = False,
|
|
53
|
+
public: bool = False,
|
|
54
|
+
private: bool = False,
|
|
55
|
+
immutable: bool = False,
|
|
56
|
+
must_revalidate: bool = False,
|
|
57
|
+
) -> Callable:
|
|
58
|
+
def decorator(func: Callable) -> Callable: # noqa: C901
|
|
59
|
+
try:
|
|
60
|
+
cache_backend = BackendProxy.get_backend()
|
|
61
|
+
except BackendNotFoundError:
|
|
62
|
+
# Fallback to memory backend if no backend is set
|
|
63
|
+
cache_backend = MemoryBackend()
|
|
64
|
+
BackendProxy.set_backend(cache_backend)
|
|
65
|
+
|
|
66
|
+
# Analyze the original function's signature
|
|
67
|
+
sig: Signature = inspect.signature(func)
|
|
68
|
+
params: list[Parameter] = list(sig.parameters.values())
|
|
69
|
+
|
|
70
|
+
# Check if Request is already in the parameters
|
|
71
|
+
found_request: Parameter | None = next(
|
|
72
|
+
(param for param in params if param.annotation == Request), None
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# Add Request parameter if it's not present
|
|
76
|
+
if not found_request:
|
|
77
|
+
request_name: str = "__cachex_request"
|
|
78
|
+
|
|
79
|
+
request_param = inspect.Parameter(
|
|
80
|
+
request_name,
|
|
81
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
82
|
+
annotation=Request,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
sig = sig.replace(parameters=[*params, request_param])
|
|
86
|
+
|
|
87
|
+
else:
|
|
88
|
+
request_name = found_request.name
|
|
89
|
+
|
|
90
|
+
func.__signature__ = sig
|
|
91
|
+
|
|
92
|
+
@wraps(func)
|
|
93
|
+
async def wrapper(*args: Any, **kwargs: Any) -> Response: # noqa: C901
|
|
94
|
+
if found_request:
|
|
95
|
+
request: Request | None = kwargs.get(request_name)
|
|
96
|
+
else:
|
|
97
|
+
request: Request | None = kwargs.pop(request_name, None)
|
|
98
|
+
|
|
99
|
+
if not request: # pragma: no cover
|
|
100
|
+
# Skip coverage for this case, as it should not happen
|
|
101
|
+
raise RequestNotFoundError()
|
|
102
|
+
|
|
103
|
+
# Only cache GET requests
|
|
104
|
+
if request.method != "GET":
|
|
105
|
+
return await get_response(func, *args, **kwargs)
|
|
106
|
+
|
|
107
|
+
# Generate cache key
|
|
108
|
+
cache_key = f"{request.url.path}:{request.query_params}"
|
|
109
|
+
|
|
110
|
+
# Check if the data is already in the cache
|
|
111
|
+
cached_data = await cache_backend.get(cache_key)
|
|
112
|
+
|
|
113
|
+
if cached_data and cached_data.etag == (
|
|
114
|
+
request.headers.get("if-none-match")
|
|
115
|
+
):
|
|
116
|
+
return Response(
|
|
117
|
+
status_code=HTTP_304_NOT_MODIFIED,
|
|
118
|
+
headers={"ETag": cached_data.etag},
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
# Get the response
|
|
122
|
+
response = await get_response(func, *args, **kwargs)
|
|
123
|
+
|
|
124
|
+
# Generate ETag (hash based on response content)
|
|
125
|
+
if isinstance(response, JSONResponse):
|
|
126
|
+
content = response.body
|
|
127
|
+
else:
|
|
128
|
+
content = (
|
|
129
|
+
response.body
|
|
130
|
+
if hasattr(response, "body")
|
|
131
|
+
else str(response).encode()
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# Calculate ETag
|
|
135
|
+
etag = f'W/"{hashlib.md5(content).hexdigest()}"' # noqa: S324
|
|
136
|
+
|
|
137
|
+
# Add ETag to response headers
|
|
138
|
+
response.headers["ETag"] = etag
|
|
139
|
+
|
|
140
|
+
# Handle Cache-Control header
|
|
141
|
+
cache_control = CacheControl()
|
|
142
|
+
|
|
143
|
+
# Handle special case: no-store (highest priority)
|
|
144
|
+
if no_store:
|
|
145
|
+
cache_control.add(DirectiveType.NO_STORE)
|
|
146
|
+
response.headers["Cache-Control"] = str(cache_control)
|
|
147
|
+
return response
|
|
148
|
+
|
|
149
|
+
# Handle special case: no-cache
|
|
150
|
+
if no_cache:
|
|
151
|
+
cache_control.add(DirectiveType.NO_CACHE)
|
|
152
|
+
if must_revalidate:
|
|
153
|
+
cache_control.add(DirectiveType.MUST_REVALIDATE)
|
|
154
|
+
response.headers["Cache-Control"] = str(cache_control)
|
|
155
|
+
return response
|
|
156
|
+
|
|
157
|
+
# Handle normal cache control cases
|
|
158
|
+
# 1. Access scope (public/private)
|
|
159
|
+
if public:
|
|
160
|
+
cache_control.add(DirectiveType.PUBLIC)
|
|
161
|
+
elif private:
|
|
162
|
+
cache_control.add(DirectiveType.PRIVATE)
|
|
163
|
+
|
|
164
|
+
# 2. Cache time settings
|
|
165
|
+
if ttl is not None:
|
|
166
|
+
cache_control.add(DirectiveType.MAX_AGE, ttl)
|
|
167
|
+
|
|
168
|
+
# 3. Validation related
|
|
169
|
+
if must_revalidate:
|
|
170
|
+
cache_control.add(DirectiveType.MUST_REVALIDATE)
|
|
171
|
+
|
|
172
|
+
# 4. Stale response handling
|
|
173
|
+
if stale is not None and stale_ttl is None:
|
|
174
|
+
raise CacheXError("stale_ttl must be set if stale is used")
|
|
175
|
+
|
|
176
|
+
if stale == "revalidate":
|
|
177
|
+
cache_control.add(DirectiveType.STALE_WHILE_REVALIDATE, stale_ttl)
|
|
178
|
+
elif stale == "error":
|
|
179
|
+
cache_control.add(DirectiveType.STALE_IF_ERROR, stale_ttl)
|
|
180
|
+
|
|
181
|
+
# 5. Special flags
|
|
182
|
+
if immutable:
|
|
183
|
+
cache_control.add(DirectiveType.IMMUTABLE)
|
|
184
|
+
|
|
185
|
+
# Store the data in the cache
|
|
186
|
+
await cache_backend.set(cache_key, ETagContent(etag, content), ttl=ttl)
|
|
187
|
+
|
|
188
|
+
response.headers["Cache-Control"] = str(cache_control)
|
|
189
|
+
return response
|
|
190
|
+
|
|
191
|
+
return wrapper
|
|
192
|
+
|
|
193
|
+
return decorator
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DirectiveType(Enum):
|
|
5
|
+
"""Enum representing Cache-Control directives."""
|
|
6
|
+
|
|
7
|
+
MAX_AGE = "max-age"
|
|
8
|
+
S_MAXAGE = "s-maxage"
|
|
9
|
+
NO_CACHE = "no-cache"
|
|
10
|
+
NO_STORE = "no-store"
|
|
11
|
+
NO_TRANSFORM = "no-transform"
|
|
12
|
+
MUST_REVALIDATE = "must-revalidate"
|
|
13
|
+
PROXY_REVALIDATE = "proxy-revalidate"
|
|
14
|
+
MUST_UNDERSTAND = "must-understand"
|
|
15
|
+
PRIVATE = "private"
|
|
16
|
+
PUBLIC = "public"
|
|
17
|
+
IMMUTABLE = "immutable"
|
|
18
|
+
STALE_WHILE_REVALIDATE = "stale-while-revalidate"
|
|
19
|
+
STALE_IF_ERROR = "stale-if-error"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class CacheXError(Exception):
|
|
2
|
+
"""Base class for all exceptions in FastAPI-CacheX."""
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class CacheError(CacheXError):
|
|
6
|
+
"""Exception raised for cache-related errors."""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class BackendNotFoundError(CacheXError):
|
|
10
|
+
"""Exception raised when a cache backend is not found."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class RequestNotFoundError(CacheXError):
|
|
14
|
+
"""Exception raised when a request is not found."""
|
fastapi_cachex/proxy.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from fastapi_cachex.backends import BaseCacheBackend
|
|
2
|
+
from fastapi_cachex.exceptions import BackendNotFoundError
|
|
3
|
+
|
|
4
|
+
_default_backend: BaseCacheBackend | None = None
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class BackendProxy:
|
|
8
|
+
"""FastAPI CacheX Proxy"""
|
|
9
|
+
|
|
10
|
+
@staticmethod
|
|
11
|
+
def get_backend() -> BaseCacheBackend:
|
|
12
|
+
if _default_backend is None:
|
|
13
|
+
raise BackendNotFoundError(
|
|
14
|
+
"Backend is not set. Please set the backend first."
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
return _default_backend
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
def set_backend(backend: BaseCacheBackend) -> None:
|
|
21
|
+
"""Set the backend for caching."""
|
|
22
|
+
global _default_backend
|
|
23
|
+
_default_backend = backend
|
fastapi_cachex/types.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Any
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class ETagContent:
|
|
8
|
+
"""ETag and content for cache items."""
|
|
9
|
+
|
|
10
|
+
etag: str
|
|
11
|
+
content: Any
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class CacheItem:
|
|
16
|
+
"""Cache item with optional expiry time."""
|
|
17
|
+
|
|
18
|
+
value: ETagContent
|
|
19
|
+
expiry: Optional[int] = None
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastapi-cachex
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: fastapi>=0.115.12
|
|
9
|
+
Requires-Dist: httpx>=0.28.1
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# FastAPI-Cache X
|
|
13
|
+
|
|
14
|
+
[](https://github.com/astral-sh/uv)
|
|
15
|
+
[](https://github.com/astral-sh/ruff)
|
|
16
|
+
[](https://github.com/allen0099/FastAPI-CacheX/actions/workflows/test.yml)
|
|
17
|
+
[](https://github.com/allen0099/FastAPI-CacheX/actions/workflows/test.yml)
|
|
18
|
+
|
|
19
|
+
[](https://badge.fury.io/py/fastapi-cachex)
|
|
20
|
+
[](https://pypi.org/project/fastapi-cachex/)
|
|
21
|
+
|
|
22
|
+
[English](README.md) | [繁體中文](docs/README.zh-TW.md)
|
|
23
|
+
|
|
24
|
+
A high-performance caching extension for FastAPI, providing comprehensive HTTP caching support.
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
- Support for HTTP caching headers
|
|
29
|
+
- `Cache-Control`
|
|
30
|
+
- `ETag`
|
|
31
|
+
- `If-None-Match`
|
|
32
|
+
- Multiple backend cache support
|
|
33
|
+
- Redis
|
|
34
|
+
- Memcached
|
|
35
|
+
- In-memory cache
|
|
36
|
+
- Complete Cache-Control directive implementation
|
|
37
|
+
- Easy-to-use `@cache` decorator
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
### Using pip
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install fastapi-cachex
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Using uv (recommended)
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
uv pip install fastapi-cachex
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Quick Start
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from fastapi import FastAPI
|
|
57
|
+
from fastapi_cachex import cache
|
|
58
|
+
|
|
59
|
+
app = FastAPI()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@app.get("/")
|
|
63
|
+
@cache()
|
|
64
|
+
async def read_root():
|
|
65
|
+
return {"Hello": "World"}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Development Guide
|
|
69
|
+
|
|
70
|
+
### Running Tests
|
|
71
|
+
|
|
72
|
+
1. Run unit tests:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pytest
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
2. Run tests with coverage report:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pytest --cov=fastapi_cachex
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Using tox
|
|
85
|
+
|
|
86
|
+
tox ensures the code works across different Python versions (3.10-3.13).
|
|
87
|
+
|
|
88
|
+
1. Install all Python versions
|
|
89
|
+
2. Run tox:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
tox
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
To run for a specific Python version:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
tox -e py310 # only run for Python 3.10
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Contributing
|
|
102
|
+
|
|
103
|
+
1. Fork the project
|
|
104
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
105
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
106
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
107
|
+
5. Open a Pull Request
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
fastapi_cachex/__init__.py,sha256=K8zRD7pEOo77Ged7SJQ-BFNMe6Pnz8yM5ePFq97nI_s,82
|
|
2
|
+
fastapi_cachex/cache.py,sha256=oMMPPcGISUWUuzVFhnd3KlgnL4ooMZErJVMQxieYy3A,6631
|
|
3
|
+
fastapi_cachex/directives.py,sha256=kJCmsbyQ89m6tsWo_c1vVJn3rk0pD5JZaY8xtNLcRh0,530
|
|
4
|
+
fastapi_cachex/exceptions.py,sha256=coYct4u6uK_pdjetUWDwM5OUCfhql0OkTECynMRUq4M,379
|
|
5
|
+
fastapi_cachex/proxy.py,sha256=4o38sdf1mT3dgFaY06dk9ADojfBUiFhZkxdaEg5dVo4,654
|
|
6
|
+
fastapi_cachex/types.py,sha256=YkXlBARIr5lHQE4PYQrwXjEoLHdz9CIjfX7V-S9N8p0,328
|
|
7
|
+
fastapi_cachex/backends/__init__.py,sha256=khEnP_GmZHJXAjfqZ35uQRYMtJQTmcQxNC2y2r8Pz5w,106
|
|
8
|
+
fastapi_cachex/backends/base.py,sha256=eGfn0oZNQ8_drNHz4ZtqBVFSxKxEwW8y4ojw5iShgLQ,707
|
|
9
|
+
fastapi_cachex/backends/memory.py,sha256=-69k5-HwNzAPumemy-17LBZuBzUcA-qYhz2qCzVTOCc,2419
|
|
10
|
+
fastapi_cachex-0.1.0.dist-info/licenses/LICENSE,sha256=asJkHbd10YDSnjeAOIlKafh7E_exwtKXY5rA-qc_Mno,11339
|
|
11
|
+
fastapi_cachex-0.1.0.dist-info/METADATA,sha256=Ugbv0EXwcJanK6xLavSN6dKGapu1k8IiKZC6wgPRUpY,2705
|
|
12
|
+
fastapi_cachex-0.1.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
13
|
+
fastapi_cachex-0.1.0.dist-info/top_level.txt,sha256=97FfG5FDycd3hks-_JznEr-5lUOgg8AZd8pqK5imWj0,15
|
|
14
|
+
fastapi_cachex-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 allen0099
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fastapi_cachex
|