<commit_before>package com.excelian.mache.core;

import com.fasterxml.uuid.Generators;
import com.google.common.cache.*;

import java.util.UUID;


public class MacheImpl<K, V> implements Mache<K, V> {

    private final ForwardingCache<K, V> fwdCache;
    final private MacheLoader cacheLoader;
    private final UUID cacheId;

    //XXX weak keys cause invalidation tto fail because of using identity function for quivalence see http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/cache/CacheBuilder.html#weakKeys()
    //private volatile String spec = "maximumSize=10000,weakKeys,softValues,expireAfterWrite=1d,expireAfterAccess=1d,recordStats";
    private volatile String spec = "maximumSize=10000,softValues,expireAfterWrite=1d,expireAfterAccess=1d,recordStats";

    private final LoadingCache<K, V> cache;
    private volatile boolean created;

    public MacheImpl(final MacheLoader cacheLoader, String... optionalSpec) {
        this.cacheLoader = cacheLoader;
        if (optionalSpec != null && optionalSpec.length > 0) this.spec = optionalSpec[0];

        cache = CacheBuilder.from(spec)
                .recordStats()/*.removalListener((RemovalListener<K,V>) cacheLoader)*/
                .build((CacheLoader<K, V>) cacheLoader);

        fwdCache = new ForwardingCache<K, V>() {
            @Override
            protected Cache<K, V> delegate() {
                return cache;
            }

            @Override
            public void put(K key, V value) {
                delegate().put(key, value);
            }

            @Override
            public void invalidate(Object key) {
                delegate().invalidate(key);
            }
        };

        cacheId = Generators.nameBasedGenerator().generate(getName() + String.valueOf(this));
    }

    @Override
    public String getName() {
        return cacheLoader.getName();
    }

    @Override
    public UUID getId() {
        return cacheId;
    }

    @Override
    public V get(final K k) {
        createMaybe(k);
        // a bit crappy - but the fwdrCache doesnt expose 'getOrLoad(K, Loader)'

        final V result = cache.getUnchecked(k);
        return result;
    }

    @Override
    public void put(K k, V v) {

        createMaybe(k);
        fwdCache.invalidate(k);
        cacheLoader.put(k, v);
    }
<commit_msg>Correct generics and remove redundant comments<commit_after>package com.excelian.mache.core;

import com.fasterxml.uuid.Generators;
import com.google.common.cache.*;

import java.util.UUID;


public class MacheImpl<K, V> implements Mache<K, V> {

    private final ForwardingCache<K, V> fwdCache;
    final private MacheLoader<K, V, ?> cacheLoader;
    private final UUID cacheId;

    //XXX weak keys cause invalidation tto fail because of using identity function for quivalence see http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/cache/CacheBuilder.html#weakKeys()
    //private volatile String spec = "maximumSize=10000,weakKeys,softValues,expireAfterWrite=1d,expireAfterAccess=1d,recordStats";
    private volatile String spec = "maximumSize=10000,softValues,expireAfterWrite=1d,expireAfterAccess=1d,recordStats";

    private final LoadingCache<K, V> cache;
    private volatile boolean created;

    public MacheImpl(final MacheLoader<K, V, ?> cacheLoader, String... optionalSpec) {
        this.cacheLoader = cacheLoader;
        if (optionalSpec != null && optionalSpec.length > 0) this.spec = optionalSpec[0];

        cache = CacheBuilder.from(spec)
                .recordStats()
                .build((CacheLoader<K, V>) cacheLoader);

        fwdCache = new ForwardingCache<K, V>() {
            @Override
            protected Cache<K, V> delegate() {
                return cache;
            }

            @Override
            public void put(K key, V value) {
                delegate().put(key, value);
            }

            @Override
            public void invalidate(Object key) {
                delegate().invalidate(key);
            }
        };

        cacheId = Generators.nameBasedGenerator().generate(getName() + String.valueOf(this));
    }

    @Override
    public String getName() {
        return cacheLoader.getName();
    }

    @Override
    public UUID getId() {
        return cacheId;
    }

    @Override
    public V get(final K k) {
        createMaybe(k);
        //the fwdrCache doesnt expose 'getOrLoad(K, Loader)'
        return cache.getUnchecked(k);
    }

    @Override
    public void put(K k, V v) {

        createMaybe(k);
        fwdCache.invalidate(k);
        cacheLoader.put(k, v);
    }

{'fraction_non_alphanumeric': 0.10543407663996536, 'fraction_numerical': 0.006927906473262611, 'mean_word_length': 2.5294117647058822, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 22, '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': '6342882', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1296, 'n_words': 318}