package com.rnboat.framework.diskcache;

import android.support.v4.util.LruCache;

import com.rnboat.framework.diskcache.lru.Util;


/**
 * A class that generates and caches safe and unique string file names
 */
public class SafeKeyGenerator {
    private final LruCache<String, String> loadIdToSafeHash = new LruCache<>(100);

    public String getSafeKey(String key) {
        String safeKey;
        synchronized (loadIdToSafeHash) {
            safeKey = loadIdToSafeHash.get(key);
        }
        if (safeKey == null) {
            safeKey = Util.md5(key);
        }
        synchronized (loadIdToSafeHash) {
            loadIdToSafeHash.put(key, safeKey);
        }
        return safeKey;
    }


}
