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()