Example #1
0
def get_listed_products(context,
                        n_products,
                        ordering=None,
                        filter_dict=None,
                        orderable_only=True,
                        extra_filters=None):
    """
    A cached version of _get_listed_products
    """
    request = context["request"]

    key, products = context_cache.get_cached_value(
        identifier="listed_products",
        item=cache_utils.get_listed_products_cache_item(request.shop),
        context=request,
        n_products=n_products,
        ordering=ordering,
        filter_dict=filter_dict,
        orderable_only=orderable_only,
        extra_filters=hash(str(extra_filters)))
    if products is not None:
        return products

    products = _get_listed_products(context,
                                    n_products,
                                    ordering=ordering,
                                    filter_dict=filter_dict,
                                    orderable_only=orderable_only,
                                    extra_filters=extra_filters)
    products = cache_product_things(request, products)
    context_cache.set_cached_value(
        key, products, settings.SHUUP_TEMPLATE_HELPERS_CACHE_DURATION)
    return products
Example #2
0
def get_listed_products(context, n_products, ordering=None, filter_dict=None, orderable_only=True, extra_filters=None):
    """
    A cached version of _get_listed_products
    """
    request = context["request"]

    key, products = context_cache.get_cached_value(
        identifier="listed_products",
        item=cache_utils.get_listed_products_cache_item(request.shop),
        context=request,
        n_products=n_products,
        ordering=ordering,
        filter_dict=filter_dict,
        orderable_only=orderable_only,
        extra_filters=hash(str(extra_filters))
    )
    if products is not None:
        return products

    products = _get_listed_products(
        context,
        n_products,
        ordering=ordering,
        filter_dict=filter_dict,
        orderable_only=orderable_only,
        extra_filters=extra_filters
    )
    products = cache_product_things(request, products)
    context_cache.set_cached_value(key, products, settings.SHUUP_TEMPLATE_HELPERS_CACHE_DURATION)
    return products
Example #3
0
 def bump_cache_for_shop_id(shop_id):
     context_cache.bump_cache_for_item(
         cache_utils.get_listed_products_cache_item(shop_id))
     context_cache.bump_cache_for_item(
         cache_utils.get_best_selling_products_cache_item(shop_id))
     context_cache.bump_cache_for_item(
         cache_utils.get_newest_products_cache_item(shop_id))
     context_cache.bump_cache_for_item(
         cache_utils.get_products_for_category_cache_item(shop_id))
     context_cache.bump_cache_for_item(
         cache_utils.get_random_products_cache_item(shop_id))
Example #4
0
def handle_context_cache_item_bumped(sender, item, **kwargs):
    """
    Every time the context cache is bumped for a ShopProduct
    we bump the context cache for template helpers for the item's shop
    """
    if isinstance(item, ShopProduct):
        shop = item.shop
        context_cache.bump_cache_for_item(cache_utils.get_listed_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_best_selling_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_newest_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_products_for_category_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_random_products_cache_item(shop))
        bump_product_queryset_cache()

    elif isinstance(item, Product):
        bump_product_queryset_cache()
Example #5
0
def handle_context_cache_item_bumped(sender, item, **kwargs):
    """
    Every time the context cache is bumped for a ShopProduct
    we bump the context cache for template helpers for the item's shop
    """
    if isinstance(item, ShopProduct):
        shop = item.shop
        context_cache.bump_cache_for_item(
            cache_utils.get_listed_products_cache_item(shop))
        context_cache.bump_cache_for_item(
            cache_utils.get_best_selling_products_cache_item(shop))
        context_cache.bump_cache_for_item(
            cache_utils.get_newest_products_cache_item(shop))
        context_cache.bump_cache_for_item(
            cache_utils.get_products_for_category_cache_item(shop))
        context_cache.bump_cache_for_item(
            cache_utils.get_random_products_cache_item(shop))
Example #6
0
def handle_context_cache_item_bumped(sender, item, shop=None, **kwargs):
    """
    Every time the context cache is bumped for a ShopProduct
    we bump the context cache for template helpers for the item's shop
    """
    if issubclass(sender, ShopProduct):
        if not shop and isinstance(item, int):
            shop = ShopProduct.objects.get(id=item).shop
        elif not shop:
            shop = item.shop
        context_cache.bump_cache_for_item(cache_utils.get_listed_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_best_selling_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_newest_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_products_for_category_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_random_products_cache_item(shop))
        bump_product_queryset_cache()

    elif issubclass(sender, Product):
        bump_product_queryset_cache()