<commit_before>package dk.statsbiblioteket.newspaper.metadatachecker.caches;

import dk.statsbiblioteket.medieplatform.autonomous.iterator.common.AttributeParsingEvent;
import dk.statsbiblioteket.util.caching.TimeSensitiveCache;
import dk.statsbiblioteket.util.xml.DOM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import java.io.IOException;

public class DocumentCache {
    static Logger log = LoggerFactory.getLogger(DocumentCache.class);

    public TimeSensitiveCache<String,Document> documentCache = new TimeSensitiveCache<>(100,true,20);

    public DocumentCache() {
    }

    public synchronized Document getDocument(AttributeParsingEvent event)
            throws IOException {
        Document document = documentCache.get(event.getName());
        if (document == null) {
            log.debug("Parsing event '{}' as DOM, because not found in cache", event.getName());
            document = DOM.streamToDOM(event.getData(), true);
            documentCache.put(event.getName(), document);
        }
        return document;
    }
}<commit_msg>Method for specifically caching a document<commit_after>package dk.statsbiblioteket.newspaper.metadatachecker.caches;

import dk.statsbiblioteket.medieplatform.autonomous.iterator.common.AttributeParsingEvent;
import dk.statsbiblioteket.util.caching.TimeSensitiveCache;
import dk.statsbiblioteket.util.xml.DOM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import java.io.IOException;

public class DocumentCache {
    static Logger log = LoggerFactory.getLogger(DocumentCache.class);

    public TimeSensitiveCache<String,Document> documentCache = new TimeSensitiveCache<>(100,true,20);

    public DocumentCache() {
    }

    public synchronized Document getDocument(AttributeParsingEvent event)
            throws IOException {
        Document document = documentCache.get(event.getName());
        if (document == null) {
            log.debug("Parsing event '{}' as DOM, because not found in cache", event.getName());
            document = DOM.streamToDOM(event.getData(), true);
            documentCache.put(event.getName(), document);
        }
        return document;
    }

    public synchronized void cacheDocument(AttributeParsingEvent event, Document document) {
        documentCache.put(event.getName(), document);
    }
}
{'fraction_non_alphanumeric': 0.0995380092398152, 'fraction_numerical': 0.006719865602687947, 'mean_word_length': 4.025316455696203, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '5835719', 'n_tokens_mistral': 684, 'n_tokens_neox': 670, 'n_words': 134}