Skip to content

Rate Limit ignored when endpoint is cached in FastAPI. #252

@Amourspirit

Description

@Amourspirit

Rate Limit ignored when endpoint is cached in FastAPI.

In this simple example the limiter is completely ignored when I tested.

from fastapi_cache.decorator import cache

@router.get(
    "/api/v1/templates/{template_type}/{version}",
    response_class=MarkdownResponse,
)
@cache(expire=300)  # Cache for 300 seconds
@limiter.limit("15/minute")
async def get_template(
    template_type: str,
    version: str,
    request: Request,
    current_principle: dict[str, str] = Depends(get_current_active_principle),
):
    print("Fetching template:", template_type, version)
    ...

Project Dependencies

dependencies = [
    "bcrypt<4.0.0",
    "fastapi>=0.128.0",
    "fastapi-cache2>=0.2.2",
    "passlib>=1.7.4",
    "pydantic>=2.12.5",
    "pyjwt>=2.10.1",
    "python-dotenv>=1.2.1",
    "python-multipart>=0.0.21",
    "pyyaml>=6.0.3",
    "slowapi>=0.1.9",
    "toml>=0.10.2",
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions