mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-22 19:34:18 +01:00
NUT-19: Cached Requests and Responses (#624)
* fast-api-cache setup * testing the cache * fix * still not working * asynccontextmanager * move test * use redis & custom caching setup (like CDK) * make format * poetry lock * fix format string + log when a cached response is found * log when a cahced response is found * fix tests * poetry lock * try tests on github * use docker compose * maybe we dont need docker * fix types * create_task instead of run * how about we start postgres * mint features * format * remove deprecated setex call * use global expiry for all cached routes * refactor feature map and set default to 1 week * refactor feature construction * Cache NUT-19 --------- Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
@@ -28,9 +28,11 @@ from ..core.models import (
|
||||
)
|
||||
from ..core.settings import settings
|
||||
from ..mint.startup import ledger
|
||||
from .cache import RedisCache
|
||||
from .limit import limit_websocket, limiter
|
||||
|
||||
router: APIRouter = APIRouter()
|
||||
router = APIRouter()
|
||||
redis = RedisCache()
|
||||
|
||||
|
||||
@router.get(
|
||||
@@ -237,6 +239,7 @@ async def websocket_endpoint(websocket: WebSocket):
|
||||
),
|
||||
)
|
||||
@limiter.limit(f"{settings.mint_transaction_rate_limit_per_minute}/minute")
|
||||
@redis.cache()
|
||||
async def mint(
|
||||
request: Request,
|
||||
payload: PostMintRequest,
|
||||
@@ -314,6 +317,7 @@ async def get_melt_quote(request: Request, quote: str) -> PostMeltQuoteResponse:
|
||||
),
|
||||
)
|
||||
@limiter.limit(f"{settings.mint_transaction_rate_limit_per_minute}/minute")
|
||||
@redis.cache()
|
||||
async def melt(request: Request, payload: PostMeltRequest) -> PostMeltQuoteResponse:
|
||||
"""
|
||||
Requests tokens to be destroyed and sent out via Lightning.
|
||||
@@ -336,6 +340,7 @@ async def melt(request: Request, payload: PostMeltRequest) -> PostMeltQuoteRespo
|
||||
),
|
||||
)
|
||||
@limiter.limit(f"{settings.mint_transaction_rate_limit_per_minute}/minute")
|
||||
@redis.cache()
|
||||
async def swap(
|
||||
request: Request,
|
||||
payload: PostSwapRequest,
|
||||
|
||||
Reference in New Issue
Block a user