<commit_before>from django.utils import http
from . import CACHED_VIEW_PREFIX, rcache, COUCH_CACHE_TIMEOUT, CACHE_VIEWS
import simplejson


class GenerationCache(object):
    generation_key = None
    doc_types = []
    views = []

    @staticmethod
    def _get_generational_caches():
        if not getattr(GenerationCache, '_generational_caches', None):
            GenerationCache._generate_caches()
        return getattr(GenerationCache, '_generational_caches')

    @staticmethod
    def view_generation_map():
        view_map = {}
        for gen_model in GenerationCache._get_generational_caches():
            for view_name in gen_model.views:
                view_map[view_name] = gen_model
        return view_map

    @staticmethod
    def doc_type_generation_map():
        doc_type_map = {}
        for gen_model in GenerationCache._get_generational_caches():
            for doc_type in gen_model.doc_types:
                doc_type_map[doc_type] = gen_model
        return doc_type_map

    @staticmethod
    def _generate_caches():
        generational_caches = []
        for gen_model in GenerationCache.__subclasses__():
            generational_caches.append(gen_model())
        setattr(GenerationCache, '_generational_caches', generational_caches)
<commit_msg>make explicit lookup of cache backend bootstrap<commit_after>from django.utils import http, importlib
from . import CACHED_VIEW_PREFIX, rcache, COUCH_CACHE_TIMEOUT, CACHE_VIEWS
from django.conf import settings
import simplejson


class GenerationCache(object):
    generation_key = None
    doc_types = []
    views = []

    @staticmethod
    def _get_generational_caches():
        if not getattr(GenerationCache, '_generational_caches', None):
            GenerationCache._generate_caches()
        return getattr(GenerationCache, '_generational_caches')

    @staticmethod
    def view_generation_map():
        view_map = {}
        for gen_model in GenerationCache._get_generational_caches():
            for view_name in gen_model.views:
                view_map[view_name] = gen_model
        return view_map

    @staticmethod
    def doc_type_generation_map():
        doc_type_map = {}
        for gen_model in GenerationCache._get_generational_caches():
            for doc_type in gen_model.doc_types:
                doc_type_map[doc_type] = gen_model
        return doc_type_map

    @staticmethod
    def _generate_caches():
        generational_caches = []

        for cache_str in settings.COUCH_CACHE_BACKENDS:
            mod_path, cache_class_name = cache_str.rsplit('.', 1)
            mod = importlib.import_module(mod_path)
            gen_model = getattr(mod, cache_class_name)
            generational_caches.append(gen_model())
        setattr(GenerationCache, '_generational_caches', generational_caches)

{'fraction_non_alphanumeric': 0.07059240865555161, 'fraction_numerical': 0.000354735721887194, 'mean_word_length': 3.0575539568345325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3508627', 'n_tokens_mistral': 823, 'n_tokens_neox': 801, 'n_words': 168}