Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlx Ki
Python Web Development Techdegree Graduate 14,822 PointsCaching and throttling.
Hi, Kenneth Love !
I tried to set up caching (MemcachedCache and DummyCache).
This is how I set up cache:
- Installed python-memcached.
-
Set CACHED in settings.py:
CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', 'LOCATION': '127.0.0.1:8000', } }
Created cache table (python manage.py createcachetable)
Then I tried it with postman:
It looks like throttling doesn't work with cache enabled.
I send a token-authorized get request to "http://127.0.0.1:8000/api/v2/courses/".
I get back correct response, but throttling doesn't stop me.
I get this in console, after each request:
code 400, message Bad HTTP/0.9 request type ('get')
"get :1:throttle_user_1" 400 -
"GET /api/v2/courses/ HTTP/1.1" 200 490
The same result with DummyCache.
What am I doing wrong?
Sincerely, Alexey.
Update: Is something wrong with LOCATION? (changet it to '127.0.0.1:11211') like in docs, console output changed to
GET /api/v2/courses/ HTTP/1.1 200 490
on same request, but throttling still doesn't work.
1 Answer
Kenneth Love
Treehouse Guest TeacherYeah, I'd think your cache location should be the memcached address.
Can you show whatever code you have for the throttle? And how are you testing that it isn't working? Just getting requests through when they should be blocked?
Alx Ki
Python Web Development Techdegree Graduate 14,822 PointsAlx Ki
Python Web Development Techdegree Graduate 14,822 PointsThank you for response, Kenneth Love !
Didn't find how to set up MemCached for local development. LOCATION etc..
The same as in example from your video. I just added CACHES to settings.py
I just send authorized requests from Postman until "Request was throttled..." response.
Also: In the docs there is another option actually made for local development, called DummyCaching:
When I add this chunk of code to settings.py throttling also stops working.