public void setNormalizationCacheSize(int cacheSize) { CacheMap<String,String> newNormalizedCache = new CacheMap<>(cacheSize); newNormalizedCache.putAll(normalizedCache); normalizedCache = newNormalizedCache; }
/** * Creates a new file-backed CacheMap or loads it in from the specified file * if it already exists. The parameters passed in are the same as the * constructor. If useFileParams is true and the file exists, all of your * parameters will be ignored (replaced with those stored in the file * itself). If useFileParams is false then we override the settings in the * file with the ones you specify (except loadFactor and accessOrder) and * reset the stats. */ public static <K,V> CacheMap<K,V> create(int numEntries, float loadFactor, boolean accessOrder, String file, boolean useFileParams) { try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) { CacheMap<K, V> c = ErasureUtils.uncheckedCast(ois.readObject()); log.info("Read cache from " + file + ", contains " + c.size() + " entries. Backing file is " + c.backingFile); if (!useFileParams) { c.backingFile = file; c.hits = c.misses = c.puts = 0; c.CACHE_ENTRIES = numEntries; } return c; } catch (FileNotFoundException ex) { log.info("Cache file " + file + " has not been created yet. Making new one."); return new CacheMap<>(numEntries, loadFactor, accessOrder, file); } catch (Exception ex) { log.info("Error reading cache file " + file + ". Making a new cache and NOT backing to file."); return new CacheMap<>(numEntries, loadFactor, accessOrder); } }
public void setNormalizationCacheSize(int cacheSize) { CacheMap<String,String> newNormalizedCache = new CacheMap<>(cacheSize); newNormalizedCache.putAll(normalizedCache); normalizedCache = newNormalizedCache; }
public void setNormalizationCacheSize(int cacheSize) { CacheMap<String,String> newNormalizedCache = new CacheMap<>(cacheSize); newNormalizedCache.putAll(normalizedCache); normalizedCache = newNormalizedCache; }
public void setNormalizationCacheSize(int cacheSize) { CacheMap<String,String> newNormalizedCache = new CacheMap<String,String>(cacheSize); newNormalizedCache.putAll(normalizedCache); normalizedCache = newNormalizedCache; }
/** * Creates a new file-backed CacheMap or loads it in from the specified file * if it already exists. The parameters passed in are the same as the * constructor. If useFileParams is true and the file exists, all of your * parameters will be ignored (replaced with those stored in the file * itself). If useFileParams is false then we override the settings in the * file with the ones you specify (except loadFactor and accessOrder) and * reset the stats. */ public static <K,V> CacheMap<K,V> create(int numEntries, float loadFactor, boolean accessOrder, String file, boolean useFileParams) { try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file)); CacheMap<K, V> c = ErasureUtils.uncheckedCast(ois.readObject()); System.err.println("Read cache from " + file + ", contains " + c.size() + " entries. Backing file is " + c.backingFile); if (!useFileParams) { c.backingFile = file; c.hits = c.misses = c.puts = 0; c.CACHE_ENTRIES = numEntries; } return c; } catch (FileNotFoundException ex) { System.err.println("Cache file " + file + " has not been created yet. Making new one."); return new CacheMap<K, V>(numEntries, loadFactor, accessOrder, file); } catch (Exception ex) { System.err.println("Error reading cache file " + file + ". Making a new cache and NOT backing to file."); return new CacheMap<K, V>(numEntries, loadFactor, accessOrder); } }
/** * Creates a new file-backed CacheMap or loads it in from the specified file * if it already exists. The parameters passed in are the same as the * constructor. If useFileParams is true and the file exists, all of your * parameters will be ignored (replaced with those stored in the file * itself). If useFileParams is false then we override the settings in the * file with the ones you specify (except loadFactor and accessOrder) and * reset the stats. */ public static <K,V> CacheMap<K,V> create(int numEntries, float loadFactor, boolean accessOrder, String file, boolean useFileParams) { try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) { CacheMap<K, V> c = ErasureUtils.uncheckedCast(ois.readObject()); log.info("Read cache from " + file + ", contains " + c.size() + " entries. Backing file is " + c.backingFile); if (!useFileParams) { c.backingFile = file; c.hits = c.misses = c.puts = 0; c.CACHE_ENTRIES = numEntries; } return c; } catch (FileNotFoundException ex) { log.info("Cache file " + file + " has not been created yet. Making new one."); return new CacheMap<>(numEntries, loadFactor, accessOrder, file); } catch (Exception ex) { log.info("Error reading cache file " + file + ". Making a new cache and NOT backing to file."); return new CacheMap<>(numEntries, loadFactor, accessOrder); } }
/** * Creates a new file-backed CacheMap or loads it in from the specified file * if it already exists. The parameters passed in are the same as the * constructor. If useFileParams is true and the file exists, all of your * parameters will be ignored (replaced with those stored in the file * itself). If useFileParams is false then we override the settings in the * file with the ones you specify (except loadFactor and accessOrder) and * reset the stats. */ public static <K,V> CacheMap<K,V> create(int numEntries, float loadFactor, boolean accessOrder, String file, boolean useFileParams) { try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) { CacheMap<K, V> c = ErasureUtils.uncheckedCast(ois.readObject()); log.info("Read cache from " + file + ", contains " + c.size() + " entries. Backing file is " + c.backingFile); if (!useFileParams) { c.backingFile = file; c.hits = c.misses = c.puts = 0; c.CACHE_ENTRIES = numEntries; } return c; } catch (FileNotFoundException ex) { log.info("Cache file " + file + " has not been created yet. Making new one."); return new CacheMap<>(numEntries, loadFactor, accessOrder, file); } catch (Exception ex) { log.info("Error reading cache file " + file + ". Making a new cache and NOT backing to file."); return new CacheMap<>(numEntries, loadFactor, accessOrder); } }