Commit bac3a2d01c6e4ca0f19c41f541bb2cd3379b1355
1 parent
a191a186
Exists in
master
and in
39 other branches
Added cache in menu
Signed-off-by: Lucas Kanashiro <kanashiro.duarte@gmail.com> Signed-off-by: Sergio Oliveira <sergio@tracy.com.br>
Showing
1 changed file
with
12 additions
and
0 deletions
Show diff stats
colab/proxy/templatetags/proxy.py
1 | 1 | |
2 | 2 | from django.core.urlresolvers import reverse |
3 | 3 | from django import template |
4 | +from django.core.cache import cache | |
4 | 5 | |
5 | 6 | register = template.Library() |
6 | 7 | |
... | ... | @@ -20,6 +21,16 @@ PROXY_MENU_ITEM_TEMPLATE = """ |
20 | 21 | |
21 | 22 | @register.simple_tag(takes_context=True) |
22 | 23 | def proxy_menu(context): |
24 | + if context['user'].is_authenticated(): | |
25 | + cache_key = 'colab-proxy-menu-authenticated' | |
26 | + else: | |
27 | + cache_key = 'colab-proxy-menu-anonymous' | |
28 | + | |
29 | + menu_from_cache = cache.get(cache_key) | |
30 | + | |
31 | + if menu_from_cache: | |
32 | + return menu_from_cache | |
33 | + | |
23 | 34 | menu_links = {} |
24 | 35 | proxied_apps = context.get('proxy', {}) |
25 | 36 | |
... | ... | @@ -51,4 +62,5 @@ def proxy_menu(context): |
51 | 62 | link_title=unicode(text)) |
52 | 63 | menu += PROXY_MENU_TEMPLATE.format(title=unicode(title), items=items) |
53 | 64 | |
65 | + cache.set(cache_key, menu) | |
54 | 66 | return menu | ... | ... |