Merge "Fix django-compress caching issues"
This commit is contained in:
commit
b3832334af
33
horizon/cache.py
Normal file
33
horizon/cache.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.cache import caches
|
||||
from django.core.cache.utils import make_template_fragment_key
|
||||
|
||||
|
||||
def cleanup_angular_template_cache(theme):
|
||||
# The compressor has modified the angular template cache preloads
|
||||
# which are cached in the 'COMPRESS_CACHE_BACKEND' Django cache.
|
||||
django_cache = caches[settings.COMPRESS_CACHE_BACKEND]
|
||||
|
||||
# generate the same key as used in _scripts.html when caching the
|
||||
# preloads
|
||||
key = make_template_fragment_key(
|
||||
"angular",
|
||||
['template_cache_preloads', theme]
|
||||
)
|
||||
|
||||
# if template preloads have been cached, clear them
|
||||
if django_cache.get(key):
|
||||
# Set to None because memcached doesn't remove records immediately
|
||||
django_cache.set(key, None)
|
@ -15,11 +15,11 @@
|
||||
|
||||
from compressor.signals import post_compress
|
||||
from django.contrib.staticfiles import finders
|
||||
from django.core.cache import caches
|
||||
from django.core.cache.utils import make_template_fragment_key
|
||||
from django.dispatch import receiver
|
||||
from django import template
|
||||
|
||||
from horizon import cache
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@ -37,21 +37,8 @@ def update_angular_template_hash(sender, **kwargs):
|
||||
compressed = context['compressed'] # the compressed content
|
||||
compressed_name = compressed['name'] # name of the compressed content
|
||||
if compressed_name == 'angular_template_cache_preloads':
|
||||
# The compressor has modified the angular template cache preloads
|
||||
# which are cached in the 'default' Django cache. Fetch that cache.
|
||||
cache = caches['default']
|
||||
|
||||
# generate the same key as used in _scripts.html when caching the
|
||||
# preloads
|
||||
theme = context['THEME'] # current theme being compressed
|
||||
key = make_template_fragment_key(
|
||||
"angular",
|
||||
['template_cache_preloads', theme]
|
||||
)
|
||||
|
||||
# if template preloads have been cached, clear them
|
||||
if cache.get(key):
|
||||
cache.delete(key)
|
||||
cache.cleanup_angular_template_cache(theme)
|
||||
|
||||
|
||||
@register.filter(name='angular_escapes')
|
||||
|
@ -0,0 +1,24 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from horizon import cache
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Clears template cache for angularized views.'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
for theme in settings.AVAILABLE_THEMES:
|
||||
cache.cleanup_angular_template_cache(theme[0])
|
@ -0,0 +1,10 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Added an ``cleanup_angular_template_cache`` management command, that clears
|
||||
template cache for angularized views. The command is available
|
||||
as ``./manage.py cleanup_angular_template_cache``.
|
||||
fixes:
|
||||
- |
|
||||
[`bug/1874657 <https://bugs.launchpad.net/horizon/1874657>`_] Horizon
|
||||
container upgrade works without additional ``./manage.py compress`` call.
|
Loading…
Reference in New Issue
Block a user