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

com.jpattern.service.cache.ACache Maven / Gradle / Ivy

There is a newer version: 3.6.2
Show newest version
package com.jpattern.service.cache;

import java.io.Serializable;

import com.jpattern.service.cache.statistics.ICacheStatistics;

/**
 * 
 * @author Francesco Cina'
 *
 * 24/set/2011
 */
public abstract class ACache implements ICache {

	private final ICacheStatistics cacheStatistics;
	private final String name;

	public ACache(String name, ICacheStatistics cacheStatistics) {
		this.name = name;
		this.cacheStatistics = cacheStatistics;
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public final synchronized  T get(String key, Class clazz) {
		return (T) get(key);
	}
	
	@Override
	public final synchronized Serializable get(String key) {
		Serializable value = getValue(key);
		getCacheStatistics().addEntry(key, value);
        return value;
	}
	
	protected abstract Serializable getValue(String key);

	@Override
	public ICacheStatistics getCacheStatistics() {
		return cacheStatistics;
	}

	@Override
	public String getName() {
		return name;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy