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
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))
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)
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))
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))
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
def save(self, *args, **kwargs): super(Currency, self).save(*args, **kwargs) cache.bump_version('currency_precision')
def save_form(self, form): super(ThemeConfigDetailView, self).save_form(form) cache.bump_version(get_theme_cache_key(self.request.shop))
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))
def invalidate_context_condition_cache(sender, instance, **kwargs): cache.bump_version(CAMPAIGNS_CACHE_NAMESPACE) cache.bump_version(CONTEXT_CONDITION_CACHE_NAMESPACE)