Show
Ignore:
Timestamp:
03/27/08 16:59:44 (8 months ago)
Author:
JensDiemer
Message:

add a experimental new cache middleware
-merge pagestats into cache middleware
-add unitest for the cache
-move setup_debug() from the views into the common middleware
-update other tests

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/PyLucid/models.py

    r1507 r1510  
    1818import os, posixpath, pickle 
    1919 
     20from django.conf import settings 
    2021from django.db import models 
    21 from django.contrib.auth.models import User, Group 
    22 from django.contrib.auth.models import UNUSABLE_PASSWORD 
     22from django.core.cache import cache 
     23from django.contrib.auth.models import User, Group, UNUSABLE_PASSWORD 
    2324from django.utils.translation import ugettext as _ 
    24 from django.conf import settings 
    2525 
    2626from PyLucid.tools.shortcuts import getUniqueShortcut 
    2727from PyLucid.tools import crypt 
    2828from PyLucid.system.utils import get_uri_base 
     29#from PyLucid.db.cache import delete_page_cache 
    2930 
    3031 
     
    3839) 
    3940 
     41def delete_page_cache(): 
     42    """ 
     43    Delete all pages in the cache. 
     44    Needed, if: 
     45        - A template has been edited 
     46        - The menu changes (edit the page name, position, parent link) 
     47    TODO: move this function from models.py into a other nice place... 
     48    """ 
     49    for items in Page.objects.values('shortcut').iterator(): 
     50        shortcut = items["shortcut"] 
     51        cache_key = settings.PAGE_CACHE_PREFIX + shortcut 
     52        cache.delete(cache_key) 
     53 
    4054 
    4155class Page(models.Model): 
    4256    """ 
    4357    A CMS Page Object 
     58 
     59    TODO: We should refactor the "pre_save" behavior, use signals: 
     60    http://code.djangoproject.com/wiki/Signals 
    4461    """ 
    4562    # Explicite id field, so we can insert a help_text ;) 
     
    239256            self._check_parent(self.id) 
    240257 
     258        # Delete all pages in the cache. 
     259        # FIXME: This is only needed, if the menu changed: e.g.: if the page 
     260        # position, shortcut, parent cahnges... 
     261        delete_page_cache() 
     262 
    241263        # Rebuild shortcut / make shortcut unique: 
    242264        self._prepare_shortcut() 
     265 
     266        # Delete old page cache, if exist 
     267        cache_key = settings.PAGE_CACHE_PREFIX + self.shortcut 
     268        cache.delete(cache_key) 
    243269 
    244270        super(Page, self).save() # Call the "real" save() method 
     
    711737            pass 
    712738 
     739        #Delete the page cache if a stylesheet was edited. 
     740        delete_page_cache() 
     741 
    713742        super(Style, self).save() # Call the "real" save() method 
    714743 
     
    729758    description = models.TextField() 
    730759    content = models.TextField() 
     760 
     761    def save(self): 
     762        """ 
     763        Delete the page cache if a template was edited. 
     764        """ 
     765        delete_page_cache() 
     766 
     767        super(Template, self).save() # Call the "real" save() method 
    731768 
    732769    class Admin: