Added caching for processed course.xml

--HG--
branch : dormsbee_performance
This commit is contained in:
Bridger Maxwell
2012-02-24 17:14:23 -05:00
parent 6ad93db8ce
commit ab0b791010

View File

@@ -170,15 +170,24 @@ def course_xml_process(tree):
def course_file(user):
''' Given a user, return course.xml
'''
# TODO: Cache.
# TODO: Cache.
filename = user.profile_cache.courseware # UserProfile.objects.get(user=user).courseware
groups = user_groups(user)
options = {'dev_content':settings.DEV_CONTENT,
'groups' : groups}
tree = course_xml_process(etree.XML(render_to_string(filename, options, namespace = 'course')))
cache_key = filename + "_processed?dev_content:" + str(options['dev_content']) + "&groups:" + str(sorted(groups))
tree_string = cache.get(cache_key)
if not tree_string:
tree = course_xml_process(etree.XML(render_to_string(filename, options, namespace = 'course')))
tree_string = etree.tostring(tree)
cache.set(cache_key, tree_string, 60)
else:
tree = etree.XML(tree_string)
return tree
def section_file(user, section):