Guest User

Untitled

a guest
Oct 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. from django.conf import settings
  2.  
  3. from tastypie.throttle import CacheDBThrottle
  4.  
  5.  
  6. class SmartCacheDBThrottle(CacheDBThrottle):
  7. """
  8. Custom throttling class to address bug in Tastypie that manifests
  9. when trying to run tests or do any kind of development with a Resource
  10. that has some kind of throttling configured. Tastypie is not smart
  11. about checking whether or not DummyCache is being used, so we'll use
  12. this to make it be smart.
  13.  
  14. Requires Django 1.3+.
  15.  
  16. """
  17. def should_be_throttled(self, identifier, **kwargs):
  18. # Tastypie barfs if you try to do anything with throttling when using
  19. # a dummy cache. In production this isn't a big deal, but in a dev
  20. # environment this is a huge PITA. Check the cache type, and if we ARE
  21. # using dummy cache, just act like we did a cache check and didn't find
  22. # the key.
  23. cache = getattr(settings, 'CACHES', {})
  24. cache_default = cache.get('default')
  25.  
  26. if cache_default and cache_default['BACKEND'].endswith('DummyCache'):
  27. return False
  28. else:
  29. return (super(SmartCacheDBThrottle, self)\
  30. .should_be_throttled(identifier, **kwargs))
Add Comment
Please, Sign In to add comment