diff options
| author | Tom Christie | 2013-08-28 13:34:14 +0100 |
|---|---|---|
| committer | Tom Christie | 2013-08-28 13:34:14 +0100 |
| commit | 97b52156cc0e96c2edb7e1b176838bfd9c22321a (patch) | |
| tree | 3f6a2643f630a28d46c3f3b929b7f184b8eac829 /rest_framework | |
| parent | d7224afe5458f0b1016a80feec31c410c335dbce (diff) | |
| download | django-rest-framework-97b52156cc0e96c2edb7e1b176838bfd9c22321a.tar.bz2 | |
Added `.cache` attribute on throttles.
Closes #1066. More localised than a new settings key, and more
flexible in that different throttles can use different behavior.
Thanks to @chicheng for the report! :)
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/throttling.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/rest_framework/throttling.py b/rest_framework/throttling.py index 65b45593..8943f22c 100644 --- a/rest_framework/throttling.py +++ b/rest_framework/throttling.py @@ -2,7 +2,7 @@ Provides various throttling policies. """ from __future__ import unicode_literals -from django.core.cache import cache +from django.core.cache import cache as default_cache from django.core.exceptions import ImproperlyConfigured from rest_framework.settings import api_settings import time @@ -39,6 +39,7 @@ class SimpleRateThrottle(BaseThrottle): Previous request information used for throttling is stored in the cache. """ + cache = default_cache timer = time.time cache_format = 'throtte_%(scope)s_%(ident)s' scope = None @@ -99,7 +100,7 @@ class SimpleRateThrottle(BaseThrottle): if self.key is None: return True - self.history = cache.get(self.key, []) + self.history = self.cache.get(self.key, []) self.now = self.timer() # Drop any requests from the history which have now passed the @@ -116,7 +117,7 @@ class SimpleRateThrottle(BaseThrottle): into the cache. """ self.history.insert(0, self.now) - cache.set(self.key, self.history, self.duration) + self.cache.set(self.key, self.history, self.duration) return True def throttle_failure(self): |
