Commits

tehfink committed 2914ca5

added basic nav tree caching

Comments (0)

Files changed (1)

cmsplugin_news/navigation.py

 from datetime import datetime
 from django.core.urlresolvers import reverse
+from django.core.cache import cache
 
 from cms.utils.navigation import NavigationNode
 
 def get_nodes(request):
     """ creates mptt style parent-child list for extending django-cms navigation (menu & breadcrumb); structured on cmsplugin_news.urls """
 
+    if cache.get('cmsplugin_news_get_nodes'):               #if nav tree exists in cache, return it immediately
+        return cache.get('cmsplugin_news_get_nodes')
+
+    #the following is only executed if there is no cached nav tree
     res = []
 
     items = News.published.all()
             item_node.childrens = []
             day_node.childrens.append(item_node)
 
-    return res
+    cache.set('cmsplugin_news_get_nodes', res)              #add nav tree to the django cache
+
+    return res