diff --git a/docs/api-guide/throttling.md b/docs/api-guide/throttling.md index 42f9c228d..9f0f7cc5e 100644 --- a/docs/api-guide/throttling.md +++ b/docs/api-guide/throttling.md @@ -70,6 +70,12 @@ Or, if you're using the `@api_view` decorator with function based views. The throttle classes provided by REST framework use Django's cache backend. You should make sure that you've set appropriate [cache settings][cache-setting]. The default value of `LocMemCache` backend should be okay for simple setups. See Django's [cache documentation][cache-docs] for more details. +You could select the cache to use, using the `THROTTLE_CACHE_ALIAS` setting. For example. + + REST_FRAMEWORK = { + 'THROTTLE_CACHE_ALIAS': 'default' + } + --- # API Reference diff --git a/docs/topics/release-notes.md b/docs/topics/release-notes.md index 626831cbf..614983db0 100644 --- a/docs/topics/release-notes.md +++ b/docs/topics/release-notes.md @@ -43,6 +43,7 @@ You can determine your currently installed version using `pip freeze`: ### Master * Support customizable view name and description functions, using the `VIEW_NAME_FUNCTION` and `VIEW_DESCRIPTION_FUNCTION` settings. +* Add `THROTTLE_CACHE_ALIAS` option to choose throttle cache. * Bugfix: `required=True` argument fixed for boolean serializer fields. * Bugfix: `client.force_authenticate(None)` should also clear session info if it exists. * Bugfix: Client sending emptry string instead of file now clears `FileField`. diff --git a/rest_framework/settings.py b/rest_framework/settings.py index 2ee15ac7c..9d8639e1f 100644 --- a/rest_framework/settings.py +++ b/rest_framework/settings.py @@ -108,6 +108,8 @@ DEFAULTS = { ), 'TIME_FORMAT': None, + 'THROTTLE_CACHE_ALIAS': 'default', + # Pending deprecation 'FILTER_BACKEND': None, } diff --git a/rest_framework/throttling.py b/rest_framework/throttling.py index 65b455930..afe155f93 100644 --- a/rest_framework/throttling.py +++ b/rest_framework/throttling.py @@ -2,11 +2,13 @@ Provides various throttling policies. """ from __future__ import unicode_literals -from django.core.cache import cache +from django.core.cache import get_cache from django.core.exceptions import ImproperlyConfigured from rest_framework.settings import api_settings import time +cache = get_cache(api_settings.THROTTLE_CACHE_ALIAS) + class BaseThrottle(object): """