From 29f7f9721c3b3a333cae823e0f1eb75691ae0ece Mon Sep 17 00:00:00 2001 From: str4d Date: Thu, 17 Jan 2013 04:24:27 +0000 Subject: [PATCH] Added caching to sitemaps The custom cache key is required so that request.url_root is part of the key, so that multiple domains pointing to the same server will get the correct cached sitemap (since the sitemap contains the domain). --- i2p2www/sitemap.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/i2p2www/sitemap.py b/i2p2www/sitemap.py index e37be0a9..ccbddf6a 100644 --- a/i2p2www/sitemap.py +++ b/i2p2www/sitemap.py @@ -1,7 +1,7 @@ from flask import make_response, render_template, request, safe_join import os.path -from i2p2www import SITE_DIR, SUPPORTED_LANGS +from i2p2www import SITE_DIR, SUPPORTED_LANGS, cache from i2p2www.blog.helpers import get_blog_slugs from i2p2www.meetings.helpers import get_meetings_ids @@ -9,6 +9,10 @@ from i2p2www.meetings.helpers import get_meetings_ids ########## # Sitemaps +def get_sitemap_cache_key(): + return 'view/%s/%s' % (request.url_root, request.path) + +@cache.cached(600, get_sitemap_cache_key) def render_sitemap_index(): # Include the / at the end, so the language can be # sandwiched between url_root and /sitemap.xml in @@ -20,6 +24,7 @@ def render_sitemap_index(): response.headers['Content-Type'] = 'application/xml' return response +@cache.cached(600, get_sitemap_cache_key) def render_sitemap(): # Include the / at the end, so the language can be # sandwiched between url_root and url.path in the