prismicio-community / python-kit

Development kit for the Python language
https://developers.prismic.io
18 stars 27 forks source link

Memcache key length > 250 #31

Open max-barry opened 7 years ago

max-barry commented 7 years ago

Liking this module and Prismic in general.

I noticed that package uses the fetch url as the cache key. If you're search query was long, or you use an ACCESS_TOKEN (the ones Prismic generate are long) in your call, then that URL is going to be really long and the key will be over 250 characters.

That will throw a hard exception in most Python memcache packages.

I'm using pylibmc but the Memcache client doesn't matter. The 250 character limit on cache keys is fundamental to Memcache.

Example of a key that threw an exception for me:

https://<MY_6_CHARACTER_DOMAIN>.prismic.io/api/v1/documents/search?access_token=<MY_ACCESS_TOKEN>&q=%5B%5B%3Ad+%3D+at%28my.content_post.uid%2C+%22my-test-slug%22%29%5D%5D&ref=Wa_fDS0AAI1WhU1d&page=1&pageSize=1

Proposed solutions Potentially don't use the hostname in the key? It's still risky that with an access token and complicated query it nudges over 250 characters.

Hash the query dictionary in some way that it creates a much shorter string than the URL.

Interim solution I'm making my Master API public and not using the access token, which is easily the longest thing in the URL.

srenault commented 7 years ago

Thanks for your report. We're going to work on this.