예제 #1
0
파일: box.py 프로젝트: joskid/ella
 def render(self):
     " Cached wrapper around self._render(). "
     if getattr(settings, 'DOUBLE_RENDER', False) and self.can_double_render:
         if 'SECOND_RENDER' not in self._context:
             return self.double_render()
     key = self.get_cache_key()
     rend = cache.get(key)
     if rend is None:
         rend = self._render()
         cache.set(key, rend, core_settings.CACHE_TIMEOUT)
         for model, test in self.get_cache_tests():
             CACHE_DELETER.register_test(model, test, key)
         CACHE_DELETER.register_pk(self.obj, key)
     return rend
예제 #2
0
파일: box.py 프로젝트: whit/ella
 def render(self):
     " Cached wrapper around self._render(). "
     if getattr(settings, 'DOUBLE_RENDER',
                False) and self.can_double_render:
         if 'SECOND_RENDER' not in self._context:
             return self.double_render()
     key = self.get_cache_key()
     rend = cache.get(key)
     if rend is None:
         rend = self._render()
         cache.set(key, rend, core_settings.CACHE_TIMEOUT)
         for model, test in self.get_cache_tests():
             CACHE_DELETER.register_test(model, test, key)
         CACHE_DELETER.register_pk(self.obj, key)
     return rend
예제 #3
0
파일: utils.py 프로젝트: chewable/ella
def get_cached_object(model, **kwargs):
    """
    Return a cached object. If the object does not exist in the cache, create it
    and register it for invalidation if the object is updated (check via _get_pk_val().

    Params:
        model - Model class ContentType instance representing the model's class
        **kwargs - lookup parameters for content_type.get_object_for_this_type and for key creation

    Throws:
        model.DoesNotExist is propagated from content_type.get_object_for_this_type
    """
    if isinstance(model, ContentType):
        model = model.model_class()

    key = _get_key(KEY_FORMAT_OBJECT, model, kwargs)

    obj = cache.get(key)
    if obj is None:
        obj = model._default_manager.get(**kwargs)
        cache.set(key, obj, CACHE_TIMEOUT)
        CACHE_DELETER.register_pk(obj, key)
    return obj
예제 #4
0
def get_cached_object(model, **kwargs):
    """
    Return a cached object. If the object does not exist in the cache, create it
    and register it for invalidation if the object is updated (check via _get_pk_val().

    Params:
        model - Model class ContentType instance representing the model's class
        **kwargs - lookup parameters for content_type.get_object_for_this_type and for key creation

    Throws:
        model.DoesNotExist is propagated from content_type.get_object_for_this_type
    """
    if isinstance(model, ContentType):
        model = model.model_class()

    key = _get_key(KEY_FORMAT_OBJECT, model, kwargs)

    obj = cache.get(key)
    if obj is None:
        obj = model._default_manager.get(**kwargs)
        cache.set(key, obj, CACHE_TIMEOUT)
        CACHE_DELETER.register_pk(obj, key)
    return obj
예제 #5
0
파일: utils.py 프로젝트: chewable/ella
def get_cached_list(model, *args, **kwargs):
    """
    Return a cached list. If the list does not exist in the cache, create it
    and register it for invalidation if any object from the list is updated (check via _get_pk_val()).

    Params:
        model - Model class ContentType instance representing the model's class
        **kwargs - lookup parameters for content_type.get_object_for_this_type and for key creation

    """
    if isinstance(model, ContentType):
        model = model.model_class()

    key = _get_key(KEY_FORMAT_LIST, model, kwargs)

    l = cache.get(key)
    if l is None:
        log.debug('get_cached_list(model=%s), object not cached.' % str(model))
        l = list(model._default_manager.filter(*args, **kwargs))
        cache.set(key, l, CACHE_TIMEOUT)
        for o in l:
            CACHE_DELETER.register_pk(o, key)
        #CACHE_DELETER.register_test(model, lambda x: model._default_manager.filter(**kwargs).filter(pk=x._get_pk_val()) == 1, key)
    return l
예제 #6
0
def get_cached_list(model, *args, **kwargs):
    """
    Return a cached list. If the list does not exist in the cache, create it
    and register it for invalidation if any object from the list is updated (check via _get_pk_val()).

    Params:
        model - Model class ContentType instance representing the model's class
        **kwargs - lookup parameters for content_type.get_object_for_this_type and for key creation

    """
    if isinstance(model, ContentType):
        model = model.model_class()

    key = _get_key(KEY_FORMAT_LIST, model, kwargs)

    l = cache.get(key)
    if l is None:
        log.debug('get_cached_list(model=%s), object not cached.' % str(model))
        l = list(model._default_manager.filter(*args, **kwargs))
        cache.set(key, l, CACHE_TIMEOUT)
        for o in l:
            CACHE_DELETER.register_pk(o, key)
        #CACHE_DELETER.register_test(model, lambda x: model._default_manager.filter(**kwargs).filter(pk=x._get_pk_val()) == 1, key)
    return l
예제 #7
0
def invalidate_cache(key, template_name, template_dirs=None):
    from ella.db_templates.models import DbTemplate
    if DbTemplate._meta.installed:
        CACHE_DELETER.register_test(DbTemplate, "name:%s" % template_name, key)
예제 #8
0
파일: core.py 프로젝트: goldsoft1206/ella
        # push context stack
        context.push()
        context[core_settings.BOX_INFO] = box_key

        # render the box
        result = box.render()
        # restore the context
        context.pop()

        # record parent box dependecy on child box or cached full-page on box
        if not (core_settings.DOUBLE_RENDER and box.can_double_render) and (core_settings.BOX_INFO in context or core_settings.ECACHE_INFO in context):
            if core_settings.BOX_INFO in context:
                source_key = context[core_settings.BOX_INFO]
            elif core_settings.ECACHE_INFO in context:
                source_key = context[core_settings.ECACHE_INFO]
            CACHE_DELETER.register_dependency(source_key, box_key)

        return result

@register.tag('box')
def do_box(parser, token):
    """
    Tag Node representing our idea of a reusable box. It can handle multiple
    parameters in its body which will then be accessible via ``{{ box.params
    }}`` in the template being rendered.

    .. note::
        The inside of the box will be rendered only when redering the box in
        current context and the ``object`` template variable will be present
        and set to the target of the box.
예제 #9
0
def invalidate_cache(key, template_name, template_dirs=None):
    from ella.db_templates.models import DbTemplate

    if DbTemplate._meta.installed:
        CACHE_DELETER.register_test(DbTemplate, "name:%s" % template_name, key)
예제 #10
0
파일: managers.py 프로젝트: majerm/ella
def invalidate_listing(key, self, *args, **kwargs):
    CACHE_DELETER.register_test(self.model, '', key)
예제 #11
0
파일: core.py 프로젝트: yulongsun/ella
def register_test(key, object, content_path):
    CACHE_DELETER.register_pk(object, key)
예제 #12
0
파일: models.py 프로젝트: dhruvAdhia/ella
def invalidate_cache(key,  self, object, **kwargs):
    target_ct = ContentType.objects.get_for_model(object)
    CACHE_DELETER.register_test(Comment, "target_id:%s;target_ct_id:%s" % (object.pk, target_ct.pk) , key)
예제 #13
0
def gallery_cache_invalidator(key, gallery, *args, **kwargs):
    """Registers gallery cache invalidator test in the cache system."""
    CACHE_DELETER.register_pk(gallery, key)
    CACHE_DELETER.register_test(GalleryItem, 'gallery_id:%s' % gallery.pk, key)
예제 #14
0
def invalidate_cache(key,  self, object, **kwargs):
    target_ct = ContentType.objects.get_for_model(object)
    CACHE_DELETER.register_test(Comment, "target_id:%s;target_ct_id:%s" % (object.pk, target_ct.pk) , key)
예제 #15
0
파일: models.py 프로젝트: goldsoft1206/ella
def gallery_cache_invalidator(key, gallery, *args, **kwargs):
    """Registers gallery cache invalidator test in the cache system."""
    CACHE_DELETER.register_pk(gallery, key)
    CACHE_DELETER.register_test(GalleryItem, 'gallery_id:%s' % gallery.pk, key)
예제 #16
0
파일: managers.py 프로젝트: dhruvAdhia/ella
def invalidate_listing(key, self, *args, **kwargs):
    CACHE_DELETER.register_test(self.model, '', key)
예제 #17
0
파일: core.py 프로젝트: whit/ella
        context[core_settings.BOX_INFO] = box_key

        # render the box
        result = box.render()
        # restore the context
        context.pop()

        # record parent box dependecy on child box or cached full-page on box
        if not (core_settings.DOUBLE_RENDER and box.can_double_render) and (
                core_settings.BOX_INFO in context
                or core_settings.ECACHE_INFO in context):
            if core_settings.BOX_INFO in context:
                source_key = context[core_settings.BOX_INFO]
            elif core_settings.ECACHE_INFO in context:
                source_key = context[core_settings.ECACHE_INFO]
            CACHE_DELETER.register_dependency(source_key, box_key)

        return result


@register.tag('box')
def do_box(parser, token):
    """
    Tag Node representing our idea of a reusable box. It can handle multiple
    parameters in its body which will then be accessible via ``{{ box.params
    }}`` in the template being rendered.

    .. note::
        The inside of the box will be rendered only when redering the box in
        current context and the ``object`` template variable will be present
        and set to the target of the box.