Example #1
0
def test_cache_api():
    key = "test_prefix:123"
    value = "456"
    cache.set(key, value)
    assert cache.get(key) == value
    cache.bump_version(key)
    assert cache.get(key, default="derp"
                     ) == "derp"  # version was bumped, so no way this is there
    cache.set(key, value)
    assert cache.get(key) == value
Example #2
0
def bump_cache_for_item(item):
    """
    Bump cache for given item

    Use this only for non product items. For products
    and shop_products use `bump_cache_for_product` and
    `bump_cache_for_shop_product` for those.

    :param item: Cached object
    """
    cache.bump_version(_get_namespace_for_item(item))
Example #3
0
def set_configuration(shop=None, category=None, data=None):
    if category and category.pk:
        configuration.set(None, _get_category_configuration_key(category), data)
    elif shop:
        configuration.set(shop, FACETED_DEFAULT_CONF_KEY, data)
        cache.bump_version(get_theme_cache_key(shop))

    # clear active keys
    context_cache.bump_cache_for_item(category)
    if not category:
        from wshop.core.models import Category
        for cat_pk in Category.objects.all().values_list("pk", flat=True):
            context_cache.bump_cache_for_pk(Category, cat_pk)
Example #4
0
def bump_cache_for_pk(cls, pk):
    """
    Bump cache for given class and pk combination

    Use this only for non product items. For products
    and shop_products use `bump_cache_for_product` and
    `bump_cache_for_shop_product` for those.

    In case you need to use this to product or shop_product
    make sure you also bump related objects like in
    `bump_cache_for_shop_product`.

    :param cls: Class for cached object
    :param pk: pk for cached object
    """
    cache.bump_version("%s-%s" % (_get_namespace_prefix(cls), pk))
Example #5
0
    def form_valid(self, form):
        identifier = form["theme"].cleaned_data["activate"]
        data = {
            "settings": {
                "stylesheet": form["theme"].cleaned_data["selected_style"]
            }
        }
        theme_settings, created = ThemeSettings.objects.get_or_create(
            theme_identifier=identifier, shop=self.request.shop)
        if created:
            theme_settings.data = data
            theme_settings.save()
        else:
            theme_settings.update_settings(data["settings"])

        set_current_theme(identifier, self.object)
        cache.bump_version(get_theme_cache_key(self.request.shop))
Example #6
0
def set_current_theme(identifier, shop):
    """
    Activate a theme based on identifier.

    :param identifier: Theme identifier
    :type identifier: str
    :param shop: Shop to fetch the theme settings
    :type shop: wshop.core.models.Shop
    :return: Activated theme
    :rtype: Theme
    """
    cache.bump_version(get_theme_cache_key(shop))
    theme = get_theme_by_identifier(identifier, shop)
    if not theme:
        raise ValueError("Invalid theme identifier")
    theme.set_current()
    cache.set(get_theme_cache_key(shop), theme)
    set_middleware_current_theme(theme)
    return theme
Example #7
0
 def save(self, *args, **kwargs):
     super(Currency, self).save(*args, **kwargs)
     cache.bump_version('currency_precision')
Example #8
0
 def save_form(self, form):
     super(ThemeConfigDetailView, self).save_form(form)
     cache.bump_version(get_theme_cache_key(self.request.shop))
Example #9
0
def invalidate_context_filter_cache(sender, instance, **kwargs):
    cache.bump_version(CAMPAIGNS_CACHE_NAMESPACE)
    # Let's try to preserve catalog filter cache as long as possible
    cache.bump_version("%s:%s" % (CATALOG_FILTER_CACHE_NAMESPACE, instance.pk))
Example #10
0
def invalidate_context_condition_cache(sender, instance, **kwargs):
    cache.bump_version(CAMPAIGNS_CACHE_NAMESPACE)
    cache.bump_version(CONTEXT_CONDITION_CACHE_NAMESPACE)