Commits

Anonymous committed 74d551b

Added caching to StyleSheets
Bumped version

Comments (0)

Files changed (2)

gnocchi/cms/views.py

+from django.core.cache import cache
 from django.http import Http404
 from django.views.generic import DetailView
 from gnocchi.cms.models import Page, StyleSheet
     slug_field = 'name'
     mimetype = 'text/css'
 
+    def get(self, request, *args, **kwargs):
+        # Check cache
+        key = 'gnocchi_css_%s' % self.kwargs['slug']
+        response = cache.get(key)
+        if response is None:
+            response = super(StyleSheetView, self).get(request, *args, **kwargs)
+            cache.set(key, response.render())
+        return response
+
     def get_template_names(self):
         return self.object
 
     def render_to_response(self, *args, **kwargs):
         kwargs['mimetype'] = 'text/css'
         return super(StyleSheetView, self).render_to_response(*args, **kwargs)
+
+
+from django.db.models.signals import post_save
+from django.dispatch import receiver
+
+@receiver(post_save, sender=StyleSheet)
+def css_clean_cache(instance, **kwargs):
+    cache.delete('gnocchi_css_%s' % instance.name)
+
 from setuptools import setup, find_packages
 
 setup( name='gnocchi-cms',
-    version = '1.1.6',
+    version = '1.1.7',
     description = 'A simple CMS',
     author = 'Curtis Maloney',
     author_email = 'curtis@tinbrain.net',