sqlalchemy / sqlalchemy/dogpile.cache
warn / document that keymangler is generally needed w/ the function decorators
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 299
- Forks
- 50
- PR merge metrics
- No merged PRs in 30d
Description
Problem
Hi I think dogpile.cache is really awesome, however I've been encountering an issue using the memcached backend:
It looks like dogpile.cache uses __repr__ or __str__ of the parameters to the cached function for the default key. When caching a sequence, this means that the key can be very large. memcached however has a fixed key limit of 250. The solution to the error is nonobvious (implementing one's own key_mangler)
Here is the error in question
ValueError: key length 63566 too long, max is 250
> /home/user/envs/mypackage/lib/python3.7/site-packages/dogpile/cache/region.py(1360)get_or_create_for_user_func()
In the interest of usability, I would recommend adding default key_mangler, for all or certain backends. Or at least, there should be caveats section in the documentation.
Workaround Solution
Since someone else will likely encounter this, I will post my solution using the xxhash library:
from xxhash import xxh64_hexdigest
region = make_region(key_mangler=xxh64_hexdigest)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the documentation around make_region, function decorators, default key generation, and key_mangler, focusing on memcached's 250-character key limit. Decide whether the guidance should document the caveat and xxhash workaround, then verify it explains how users can avoid the reported ValueError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- memcached, python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100