refactor StaticContent id scheme to be the same as moduledata. Also expose a new 'get all content for course' which will be needed to support a asset management page.

This commit is contained in:
Chris Dodge
2012-10-03 09:07:09 -04:00
parent 70d9721d5b
commit 84bc81f7eb
8 changed files with 97 additions and 39 deletions

View File

@@ -12,7 +12,7 @@ from django.core.cache import cache
from django.db import DEFAULT_DB_ALIAS
from . import app_settings
from xmodule.contentstore.content import StaticContent
def get_instance(model, instance_or_pk, timeout=None, using=None):
"""
@@ -108,14 +108,11 @@ def instance_key(model, instance_or_pk):
getattr(instance_or_pk, 'pk', instance_or_pk),
)
def content_key(filename):
return 'content:%s' % (filename)
def set_cached_content(content):
cache.set(content_key(content.filename), content)
cache.set(content.get_id(), content)
def get_cached_content(filename):
return cache.get(content_key(filename))
def get_cached_content(location):
return cache.get(StaticContent.get_id_from_location(location))
def del_cached_content(filename):
cache.delete(content_key(filename))
def del_cached_content(location):
cache.delete(StaticContent.get_id_from_location(location))

View File

@@ -12,14 +12,14 @@ from xmodule.exceptions import NotFoundError
class StaticContentServer(object):
def process_request(self, request):
# look to see if the request is prefixed with 'c4x' tag
if request.path.startswith('/' + XASSET_LOCATION_TAG):
if request.path.startswith('/' + XASSET_LOCATION_TAG +'/'):
loc = StaticContent.get_location_from_path(request.path)
# first look in our cache so we don't have to round-trip to the DB
content = get_cached_content(request.path)
content = get_cached_content(loc)
if content is None:
# nope, not in cache, let's fetch from DB
try:
content = contentstore().find(request.path)
content = contentstore().find(loc)
except NotFoundError:
raise Http404