Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default key builder does not work with memcached #12

Closed
MrAngry opened this issue Mar 19, 2021 · 3 comments
Closed

Default key builder does not work with memcached #12

MrAngry opened this issue Mar 19, 2021 · 3 comments

Comments

@MrAngry
Copy link

MrAngry commented Mar 19, 2021

Memcached does not allow spaces in keys. Thus when using the default key builder with endpoint that has dependencies, a space can be introduced when object is being represented as string.
Problem example:

@router.get("/",
             status_code=200,
             response_model=list)
async def distinct_values(field: str,
                              es: Elasticsearch = Depends(ElasticConnector)):

This result in ValidationError

Proposed solution:

def mcache_key_builder(
    func,
    namespace: Optional[str] = "",
    request: Request = None,
    response: Response = None,
    *args,
    **kwargs,
):
    prefix = FastAPICache.get_prefix()
    cache_key = f"{prefix}:{namespace}:{func.__module__}:{func.__name__}:{args}:{kwargs}".replace(" ","")
    return cache_key
        ```
@MrAngry
Copy link
Author

MrAngry commented Mar 19, 2021

Although a better solution would be to omit dependencies in key creation altogether. Otherwise it is easy to hit 255 character max key size limit

long2ice added a commit that referenced this issue Mar 20, 2021
- Update default key builder. (#12)
@long2ice
Copy link
Owner

Fixed in dev branch

@adamantike
Copy link

@long2ice, are you planning to release a new version, with these changes that are currently only available in the dev branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants