-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add request, response if it's not in the signautre
- Loading branch information
Showing
6 changed files
with
139 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "ultra-cache" | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
description = "Simple and extensible caching for FastAPI requests" | ||
authors = ["Jegor Kitskerkin <[email protected]>"] | ||
license = "MIT" | ||
|
@@ -18,6 +18,7 @@ ruff = "^0.4.2" | |
pyright = "^1.1.361" | ||
freezegun = "^1.5.0" | ||
pytest-mock = "^3.14.0" | ||
httpx = "^0.27.0" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from fastapi.testclient import TestClient | ||
from .utils import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_cache_decorator(): | ||
response = client.get("/items/1") | ||
assert response.status_code == 200 | ||
assert response.json() == {"item_id": 1} | ||
assert response.headers.get("X-Cache") == "MISS" | ||
|
||
# Test cache hit | ||
response = client.get("/items/1") | ||
assert response.status_code == 200 | ||
assert response.json() == {"item_id": 1} | ||
assert response.headers.get("X-Cache") == "HIT" | ||
|
||
# Test cache miss | ||
response = client.get("/items/2") | ||
assert response.status_code == 200 | ||
assert response.json() == {"item_id": 2} | ||
assert response.headers.get("X-Cache") == "MISS" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from fastapi import FastAPI | ||
from ultra_cache.decorator import cache | ||
from ultra_cache.storage.inmemory import InMemoryStorage | ||
|
||
app = FastAPI() | ||
storage = InMemoryStorage() | ||
|
||
|
||
@app.get("/items/{item_id}") | ||
@cache(storage=storage) | ||
async def read_item(item_id: int): | ||
return {"item_id": item_id} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters