django-cms-mycmsproject-toporojo / menus /

# -*- coding: utf-8 -*-
from django.db import models

class CacheKeyManager(models.Manager):
    def get_keys(self, site_id=None, language=None):
        ret = self.none()
        if not site_id and not language:
            # Both site and language are None - return everything  
            ret = self.all()
        elif not site_id:
            ret = self.filter(language=language)
        elif not language:
            ret = self.filter(site=site_id)
            # Filter by site_id *and* by language.
            ret = self.filter(site=site_id).filter(language=language)
        return ret

    def get_or_create(self, **kwargs):
            return super(CacheKeyManager, self).get_or_create(**kwargs)
        except CacheKey.MultipleObjectsReturned:
            # Truncate the table, we don't want a funny cache object to cause
            # mayhem!
            return super(CacheKeyManager, self).get_or_create(**kwargs)

class CacheKey(models.Model):
    This is to store a "set" of cache keys in a fashion where it's accessible
    by multiple processes / machines.
    Multiple Django instances will then share the keys.
    This allows for selective invalidation of the menu trees (per site, per
    language), in the cache.
    language = models.CharField(max_length=255)
    site = models.PositiveIntegerField()
    key = models.CharField(max_length=255)
    objects = CacheKeyManager()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.