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 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: shoop.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)