Exemplo n.º 1
0
def update_category_cache(instance):

    # NOTE: ATM, we clear the whole cache if a category has been changed.
    # Otherwise is lasts to long when the a category has a lot of products
    # (1000s) and the shop admin changes a category.
    clear_cache()
    return
    cache.delete("%s-category-breadcrumbs-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.slug))
    cache.delete("%s-category-products-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.slug))
    cache.delete("%s-category-all-products-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.slug))
    cache.delete("%s-category-categories-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.slug))

    for category in Category.objects.all():
        cache.delete("%s-categories-portlet-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, category.slug))

    cache.delete("%s-category-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.id))
    cache.delete("%s-category-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.slug))

    cache.delete("%s-category-all-children-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.id))
    cache.delete("%s-category-children-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.id))
    cache.delete("%s-category-parents-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.id))
    cache.delete("%s-category-products-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.id))
    cache.delete("%s-category-all-products-%s" % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.id))

    # Note: As this is called "pre-saved" newly created categories don't have
    # the many-to-many attribute "products", hence we have to take care of it
    # here.
    try:
        for product in instance.products.all():
            update_product_cache(product)
    except ValueError:
        pass
Exemplo n.º 2
0
def update_category_cache(instance):

    # NOTE: ATM, we clear the whole cache if a category has been changed.
    # Otherwise is lasts to long when the a category has a lot of products
    # (1000s) and the shop admin changes a category.
    clear_cache()
    return
    cache.delete("%s-category-breadcrumbs-%s" %
                 (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.slug))
    cache.delete("%s-category-products-%s" %
                 (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.slug))
    cache.delete("%s-category-all-products-%s" %
                 (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.slug))
    cache.delete("%s-category-categories-%s" %
                 (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.slug))

    for category in Category.objects.all():
        cache.delete("%s-categories-portlet-%s" %
                     (settings.CACHE_MIDDLEWARE_KEY_PREFIX, category.slug))

    cache.delete("%s-category-%s" %
                 (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.id))
    cache.delete("%s-category-%s" %
                 (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.slug))

    cache.delete("%s-category-all-children-%s" %
                 (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.id))
    cache.delete("%s-category-children-%s" %
                 (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.id))
    cache.delete("%s-category-parents-%s" %
                 (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.id))
    cache.delete("%s-category-products-%s" %
                 (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.id))
    cache.delete("%s-category-all-products-%s" %
                 (settings.CACHE_MIDDLEWARE_KEY_PREFIX, instance.id))

    # Note: As this is called "pre-saved" newly created categories don't have
    # the many-to-many attribute "products", hence we have to take care of it
    # here.
    try:
        for product in instance.products.all():
            update_product_cache(product)
    except ValueError:
        pass
Exemplo n.º 3
0
def shop_changed_listener(sender, **kwargs):
    clear_cache()
Exemplo n.º 4
0
def shop_changed_listener(sender, **kwargs):
    clear_cache()