def METHOD_NAME(documents_config, meta_params, search_documents):
    lang = meta_params['lang']
    base_query = DBSession.query(documents_config.clazz). \
        filter(getattr(documents_config.clazz, 'redirects_to').is_(None))
    base_total_query = DBSession. \
        query(getattr(documents_config.clazz, 'document_id')). \
        filter(getattr(documents_config.clazz, 'redirects_to').is_(None))
    base_total_query = add_profile_filter(
        base_total_query, documents_config.clazz)
    base_query = add_load_for_profiles(base_query, documents_config.clazz)
    if documents_config.clazz == Outing:
        base_query = base_query. \
            order_by(documents_config.clazz.date_end.desc()). \
            order_by(documents_config.clazz.document_id.desc())
    else:
        base_query = base_query.order_by(
            documents_config.clazz.document_id.desc())
    document_ids, total = search_documents(base_query, base_total_query)
    cache_keys = get_cache_keys(
        document_ids, lang, documents_config.document_type)
    def get_documents_from_cache_keys(*cache_keys):
        """ This method is called from dogpile.cache with the cache keys
        for the documents that are not cached yet.
        """
        ids = [get_document_id(cache_key) for cache_key in cache_keys]
        docs = _get_documents_from_ids(
            ids, base_query, documents_config, lang)
        assert len(cache_keys) == len(docs), \
            'the number of returned documents must match ' + \
            'the number of keys'
        return docs
    # get the documents from the cache or from the database
    documents = get_or_create_multi(
        cache_document_listing, cache_keys, get_documents_from_cache_keys,
        should_cache_fn=lambda v: v is not None)
    documents = [doc for doc in documents if doc]
    total = total if total is not None else len(documents)
    return {
        'documents': documents,
        'total': total
    }