From 062ff7153d2bf7ef71aefc470295d95075fca9d6 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Wed, 20 Sep 2017 11:28:16 -0400 Subject: [PATCH] resurrect cchurch's license feature caching --- awx/conf/license.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/awx/conf/license.py b/awx/conf/license.py index 57456f90fa..820f4f2d58 100644 --- a/awx/conf/license.py +++ b/awx/conf/license.py @@ -2,6 +2,9 @@ # All Rights Reserved. # Django +from django.core.cache import cache +from django.core.signals import setting_changed +from django.dispatch import receiver from django.utils.translation import ugettext_lazy as _ # Django REST Framework @@ -9,6 +12,7 @@ from rest_framework.exceptions import APIException # Tower from awx.main.utils.common import get_licenser +from awx.main.utils import memoize __all__ = ['LicenseForbids', 'get_license', 'get_licensed_features', 'feature_enabled', 'feature_exists'] @@ -19,10 +23,18 @@ class LicenseForbids(APIException): default_detail = _('Your Tower license does not allow that.') +@memoize(cache_key='_validated_license_data') def _get_validated_license_data(): return get_licenser().validate() +@receiver(setting_changed) +def _on_setting_changed(sender, **kwargs): + # Clear cached result above when license changes. + if kwargs.get('setting', None) == 'LICENSE': + cache.delete('_validated_license_data') + + def get_license(show_key=False): """Return a dictionary representing the active license on this Tower instance.""" license_data = _get_validated_license_data()