Exemple #1
0
    def save(self, *args, **kwargs):
        rv = super(Category, self).save(*args, **kwargs)
        generate_multilanguage_slugs(self, self._get_slug_name)

        # bump children cache
        from E-Commerce.core import cache
        cache.bump_version("category_cached_children")

        return rv
Exemple #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))
    context_cache_item_bumped.send(getattr(item, "__class__", item), item=item)
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 E-Commerce.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)
Exemple #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))
Exemple #5
0
def test_cache_api():
    with override_settings(CACHES={
        'default': {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
            'LOCATION': 'test_configuration_cache',
        }
    }):
        cache.init_cache()

        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
Exemple #6
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=get_shop(self.request)
        )
        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(get_shop(self.request)))
Exemple #7
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: E-Commerce.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
Exemple #8
0
def set(shop, key, value):
    """
    Set configuration item value for a shop or globally.

    If given `shop` is ``None``, the value of given `key` is set
    globally for all shops.  Otherwise sets a shop specific value which
    overrides the global value in configuration of the specified shop.

    :param shop: Shop to set value for, or None to set a global value
    :type shop: E-Commerce.core.models.Shop|None
    :param key: Name of the key to set
    :type key: str
    :param value: Value to set.  Note: Must be JSON serializable.
    :type value: Any
    """
    ConfigurationItem.objects.update_or_create(
        shop=shop, key=key, defaults={"value": value})
    if shop:
        cache.set(_get_cache_key(shop), None)
    else:
        cache.bump_version(_SHOP_CONF_NAMESPACE)
Exemple #9
0
def bump_internal_cache():
    cache.bump_version("_ctx_cache")
Exemple #10
0
 def save(self, *args, **kwargs):
     super(Currency, self).save(*args, **kwargs)
     cache.bump_version('currency_precision')
Exemple #11
0
 def save(self, *args, **kwargs):
     super(Campaign, self).save(*args, **kwargs)
     cache.bump_version(CAMPAIGNS_CACHE_NAMESPACE)
     cache.bump_version(CONTEXT_CONDITION_CACHE_NAMESPACE)
     cache.bump_version(CATALOG_FILTER_CACHE_NAMESPACE)
Exemple #12
0
def bump_sales_unit_cache_signal(*args, **kwargs):
    cache.bump_version("display_unit")
Exemple #13
0
def bump_instance_thumbnail_cache(sender, instance, **kwargs):
    cache_namespace = "thumbnail_{}_{}".format(instance.pk, instance.__class__.__name__)
    cache.bump_version(cache_namespace)
Exemple #14
0
 def save_form(self, form):
     super(ThemeConfigDetailView, self).save_form(form)
     cache.bump_version(get_theme_cache_key(get_shop(self.request)))
Exemple #15
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))
Exemple #16
0
def invalidate_context_condition_cache(sender, instance, **kwargs):
    cache.bump_version(CAMPAIGNS_CACHE_NAMESPACE)
    cache.bump_version(CONTEXT_CONDITION_CACHE_NAMESPACE)