1. tehfink
  2. cmsplugin-news


tehfink  committed 2914ca5

added basic nav tree caching

  • Participants
  • Parent commits 3170e27
  • Branches cms-2.0.2

Comments (0)

Files changed (1)

File cmsplugin_news/navigation.py

View file
 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 = []
-    return res
+    cache.set('cmsplugin_news_get_nodes', res)              #add nav tree to the django cache
+    return res