All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.venky.cache.UnboundedCache Maven / Gradle / Ivy

The newest version!
package com.venky.cache;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

public abstract class UnboundedCache extends ConcurrentHashMap {

	/**
	 * 
	 */
	private static final long serialVersionUID = -279156550678934353L;
	@SuppressWarnings("unchecked")
	public V get(Object key){
		K k = (K)key;
		V v = super.get(k);
		if (v == null){
			v = getValue(k); //Wastful getValue is better than blocking GetValue.
			if (v != null){
				synchronized (this){
					V vExisting = super.get(k);
					if (vExisting == null){
						super.put(k, v);
					}else {
						v = vExisting;
					}
				}
			}
		}
		return v;
	}
	
	protected abstract V getValue(K key);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy