def __init__(self, bundle_paths=(), http_get_params=None, exclude_default_bundles=False): ''' @bundle_paths - a list containing the paths of the bundles to include @http_get_params - the request.GET query dictionary ''' http_get_params = http_get_params if http_get_params else {} self.is_debug = self._check_is_debug_mode(http_get_params) self.use_local_daemon = self._check_use_local_daemon(http_get_params) self.skip_scaffold_cache = False self.included_bundle_paths = [] # Used for the cases when you don't want to include the default bundles (style_guide) if not exclude_default_bundles: self.included_bundle_paths.extend(get_setting_default('DEFAULT_ASSET_BENDER_BUNDLES', get_setting_default('DEFAULT_BUNDLES_V3', []))) self.included_bundle_paths.extend(bundle_paths) # strip first slashes for consistency self.included_bundle_paths = [path.lstrip('/') for path in self.included_bundle_paths] self.host_project_name = get_setting_default('PROJ_NAME', None) forced_build_version_by_project = self._extract_forced_versions_from_params(http_get_params) self.s3_fetcher = S3BundleFetcher(self.host_project_name, self.is_debug, forced_build_version_by_project) is_local_debug = self.is_debug if get_bender_or_static3_setting('BENDER_LOCAL_PROJECT_MODE', False): is_local_debug = True self.local_daemon_fetcher = LocalDaemonBundleFetcher(self.host_project_name, is_local_debug, forced_build_version_by_project)
def should_ignore_caching(self, dict_of_args): ignore_locally = dict_of_args.pop('ignore_locally', None) ignore_if_setting_is_true = dict_of_args.pop('ignore_if_setting_is_true', None) # Skip caching if ignore_locally was set and we're in the local ENV if ignore_locally and get_setting_default('ENV', 'local') == 'local': return True # Skip caching if ignore_if_setting_is_true is set to some setting that is set to some Truthy value if ignore_if_setting_is_true and get_setting_default(ignore_if_setting_is_true, False): return True
def test_not_ignore_locally_2(): # Temporarily fake the ENV old_env = get_setting_default("ENV", None) _set_setting("ENV", "local") @gen_cache.wrap("some_gen", ignore_locally=False) def func_no_args(): return time() + random.randint(0, 10000000) first_result = func_no_args() ok_(first_result) second_result = func_no_args() ok_(second_result) ok_(first_result == second_result) # Reset ENV just in case _set_setting("ENV", old_env)
def load_cache(): ''' If the RAW_CACHE_NAME is defined in settings, load the cache of that name. Otherwise, load the cache that has the exact same settings as the default cache, except with no 'KEY_PREFIX' set ''' # If no django installed, we use the local memory cache if not get_cache: return simple_memory_cache cache_name = get_setting_default('RAW_CACHE_NAME', None) if cache_name: return get_cache(cache_name) conf = get_setting('CACHES').get('default') backend = conf['BACKEND'] raw_conf_dict = {} for key in ('LOCATION', 'TIMEOUT'): val = conf.get(key) if val != None: raw_conf_dict[key] = val raw_conf_dict['KEY_FUNCTION'] = lambda key, key_prefix, version: key the_cache = get_cache(backend, **raw_conf_dict) return the_cache
def get_bender_or_static3_setting(setting_name, default_value): static3_setting_name = setting_name.replace('BENDER_', 'STATIC3_') return get_setting_default(setting_name, get_setting_default(static3_setting_name, default_value))
def in_gen_cache_debug_mode(): return get_setting_default('DEBUG_GENERATIONAL_CACHE', False)