summaryrefslogtreecommitdiff
path: root/django/utils/timezone.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-11-18 21:50:03 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-11-19 21:35:39 +0100
commite23240474b4c7d630a4224a558f2e47a4b957cd1 (patch)
tree7f0c86dbb04f22226fa35421dd8cac210052e358 /django/utils/timezone.py
parentdca33ac15de81817c388234323ab358d97055689 (diff)
Simplified caching of get_default_timezone().
Diffstat (limited to 'django/utils/timezone.py')
-rw-r--r--django/utils/timezone.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/django/utils/timezone.py b/django/utils/timezone.py
index 5b83e8a3aa..a45a72f2f9 100644
--- a/django/utils/timezone.py
+++ b/django/utils/timezone.py
@@ -15,6 +15,7 @@ except ImportError:
pytz = None
from django.conf import settings
+from django.utils import lru_cache
from django.utils import six
from django.utils.decorators import ContextDecorator
@@ -162,25 +163,21 @@ def get_fixed_timezone(offset):
name = sign + hhmm
return FixedOffset(offset, name)
-# In order to avoid accessing the settings at compile time,
-# wrap the expression in a function and cache the result.
-_localtime = None
-
+# In order to avoid accessing settings at compile time,
+# wrap the logic in a function and cache the result.
+@lru_cache.lru_cache()
def get_default_timezone():
"""
Returns the default time zone as a tzinfo instance.
This is the time zone defined by settings.TIME_ZONE.
"""
- global _localtime
- if _localtime is None:
- if isinstance(settings.TIME_ZONE, six.string_types) and pytz is not None:
- _localtime = pytz.timezone(settings.TIME_ZONE)
- else:
- # This relies on os.environ['TZ'] being set to settings.TIME_ZONE.
- _localtime = LocalTimezone()
- return _localtime
+ if isinstance(settings.TIME_ZONE, six.string_types) and pytz is not None:
+ return pytz.timezone(settings.TIME_ZONE)
+ else:
+ # This relies on os.environ['TZ'] being set to settings.TIME_ZONE.
+ return LocalTimezone()
# This function exists for consistency with get_current_timezone_name