Author: batiste.bieler
Date: Mon Feb 16 05:56:47 2009
New Revision: 345
Modified:
trunk/example/settings.py
trunk/pages/admin/__init__.py
trunk/pages/models.py
trunk/pages/settings.py
trunk/pages/templates/pages/menu.html
trunk/pages/templatetags/pages_tags.py
Log:
Fix some bugs with the cache
Modified: trunk/example/settings.py
==============================================================================
--- trunk/example/settings.py (original)
+++ trunk/example/settings.py Mon Feb 16 05:56:47 2009
@@ -85,7 +85,9 @@
os.path.join(PROJECT_DIR, 'templates'),
)
-CACHE_BACKEND = "locmem:///?timeout=300&max_entries=3000"
+CACHE_BACKEND = "locmem:///?timeout=300&max_entries=6000"
+
+PAGE_CONTENT_CACHE_DURATION = 300
INSTALLED_APPS = (
'django.contrib.auth',
Modified: trunk/pages/admin/__init__.py
==============================================================================
--- trunk/pages/admin/__init__.py (original)
+++ trunk/pages/admin/__init__.py Mon Feb 16 05:56:47 2009
@@ -112,7 +112,6 @@
Content object.
"""
obj.save()
- obj.invalidate()
language = form.cleaned_data['language']
target = request.GET.get('target', None)
position = request.GET.get('position', None)
@@ -123,6 +122,8 @@
pass
else:
obj.move_to(target, position)
+
+ obj.invalidate()
for mandatory_placeholder in self.mandatory_placeholders:
Content.objects.set_or_create_content(obj, language,
Modified: trunk/pages/models.py
==============================================================================
--- trunk/pages/models.py (original)
+++ trunk/pages/models.py Mon Feb 16 05:56:47 2009
@@ -35,6 +35,8 @@
PAGE_LANGUAGES_KEY = "page_%d_languages"
PAGE_URL_KEY = "page_%d_language_%s_url"
PAGE_TEMPLATE_KEY = "page_%d_template"
+ PAGE_CHILDREN_KEY = "page_children_%d_%d"
+ PAGE_CONTENT_KEY = "page_content_%d_%s_%s"
author = models.ForeignKey(User, verbose_name=_('author'))
parent = models.ForeignKey('self', null=True, blank=True,
@@ -50,7 +52,8 @@
status = models.IntegerField(_('status'), choices=STATUSES,
default=DRAFT)
template = models.CharField(_('template'), max_length=100, null=True,
blank=True)
- sites = models.ManyToManyField(Site, default=[settings.SITE_ID],
help_text=_('The site(s) the page is accessible at.'),
verbose_name=_('sites'))
+ sites = models.ManyToManyField(Site, default=[settings.SITE_ID],
+ help_text=_('The site(s) the page is accessible at.'),
verbose_name=_('sites'))
# Managers
objects = PageManager()
@@ -102,6 +105,14 @@
for desc in self.get_descendants():
desc.invalidate_if_parent_changed()
+
+ for site in self.sites.all():
+ if self.parent:
+ cache.delete(self.PAGE_CHILDREN_KEY % (self.parent.id,
site.id))
+
+ from page.admin.utils import get_placeholders
+
+ #TODO: invalidate the content cache of the page
def invalidate_if_parent_changed(self):
"""Invalidate cache depending of a parent"""
Modified: trunk/pages/settings.py
==============================================================================
--- trunk/pages/settings.py (original)
+++ trunk/pages/settings.py Mon Feb 16 05:56:47 2009
@@ -39,7 +39,7 @@
PAGE_DEFAULT_LANGUAGE = getattr(settings, 'PAGE_DEFAULT_LANGUAGE',
settings.LANGUAGE_CODE)[:2]
# Defines how long page content should be cached, including navigation and
admin menu.
-PAGE_CONTENT_CACHE_DURATION =
getattr(settings, 'PAGE_CONTENT_CACHE_DURATION', 60)
+PAGE_CONTENT_CACHE_DURATION =
getattr(settings, 'PAGE_CONTENT_CACHE_DURATION', False)
# The id of default Site instance to be used for multisite purposes.
SITE_ID = getattr(settings, 'SITE_ID', 1)
Modified: trunk/pages/templates/pages/menu.html
==============================================================================
--- trunk/pages/templates/pages/menu.html (original)
+++ trunk/pages/templates/pages/menu.html Mon Feb 16 05:56:47 2009
@@ -1,8 +1,7 @@
{% load pages_tags cache %}
-{% cache PAGE_CONTENT_CACHE_DURATION menu page.id lang current_page.id %}
{% if page.status %}
<li>
-<a href="{% show_absolute_url page %}">{% show_content page "title" %}</a>
<span style="color:#999">{% ifequal page current_page %}selected{%
endifequal %}</span>
+<a href="{% show_absolute_url page %}">{% show_content page "slug" %}</a>
<span style="color:#999">{% ifequal page current_page %}selected{%
endifequal %}</span>
{% if children %}
<ul>
{% for child in children %}
@@ -12,4 +11,3 @@
{% endif %}
</li>
{% endif %}
-{% endcache %}
Modified: trunk/pages/templatetags/pages_tags.py
==============================================================================
--- trunk/pages/templatetags/pages_tags.py (original)
+++ trunk/pages/templatetags/pages_tags.py Mon Feb 16 05:56:47 2009
@@ -14,6 +14,7 @@
PLACEHOLDER_ERROR = _("[Placeholder %(name)s had syntax error: %(error)s]")
+# TODO: move that into the model
def get_page_children_for_site(page, site):
return page.get_children().filter(sites__domain=site.domain)
@@ -36,7 +37,12 @@
root = page.get_root()
request = context['request']
site = request.site
- children = get_page_children_for_site(page, site)
+
+ children = cache.get(Page.PAGE_CHILDREN_KEY % (page.id, site.id))
+ if children is None:
+ children = get_page_children_for_site(page, site)
+ cache.set(Page.PAGE_CHILDREN_KEY % (page.id, site.id), children)
+
if 'current_page' in context:
current_page = context['current_page']
return locals()
@@ -47,7 +53,12 @@
"""Render the admin table of pages"""
request = context['request']
site = request.site
- children = get_page_children_for_site(page, site)
+
+ children = cache.get(Page.PAGE_CHILDREN_KEY % (page.id, site.id))
+ if children is None:
+ children = get_page_children_for_site(page, site)
+ cache.set(Page.PAGE_CHILDREN_KEY % (page.id, site.id), children)
+
has_permission = page.has_page_permission(request)
# level is used to add a left margin on table row
if has_permission:
@@ -77,6 +88,7 @@
args -- content_type used by a placeholder
lang -- the wanted language (default None, use the request object to
know)
"""
+
request = context.get('request', False)
if not request or not page:
return {'content':''}
@@ -87,13 +99,17 @@
page = c[0].page
else:
return {'content':''}
+
if lang is None:
lang = get_language_from_request(context['request'])
if hasattr(settings, 'PAGE_CONTENT_CACHE_DURATION'):
- key
= 'content_cache_pid:'+str(page.id)+'_l:'+str(lang)+'_type:'+str(content_type)
+ key = Page.PAGE_CONTENT_KEY % (page.id, lang, content_type)
c = cache.get(key)
- if not c:
+ if c is None:
c = Content.objects.get_content(page, lang, content_type, True)
+ # Storing None force SQL requests
+ if c is None:
+ c = " "
cache.set(key, c, settings.PAGE_CONTENT_CACHE_DURATION)
else:
c = Content.objects.get_content(page, lang, content_type, True)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---