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

com.tsc9526.monalisa.tools.cache.impl.PerpetualCache Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
package com.tsc9526.monalisa.tools.cache.impl;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import com.tsc9526.monalisa.tools.cache.Cache;

public class PerpetualCache implements Cache {

	private String id;

	private Map cache = new HashMap();

	private ReadWriteLock readWriteLock = new ReentrantReadWriteLock();

	public PerpetualCache(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}

	public int getSize() {
		return cache.size();
	}

	public void putObject(Object key, Object value,long ttlInSeconds) {
		cache.put(key, value);
	}

	public Object getObject(Object key) {
		return cache.get(key);
	}

	public Object removeObject(Object key) {
		return cache.remove(key);
	}

	public void clear() {
		cache.clear();
	}

	public ReadWriteLock getReadWriteLock() {
		return readWriteLock;
	}

	public boolean equals(Object o) {
		if (getId() == null){
			throw new RuntimeException("Cache instances require an ID.");
		}
		
		if (this == o){
			return true;
		}
		
		if (!(o instanceof Cache)){
			return false;
		}

		Cache otherCache = (Cache) o;
		return getId().equals(otherCache.getId());
	}

	public int hashCode() {
		if (getId() == null){
			throw new RuntimeException("Cache instances require an ID.");
		}
		
		return getId().hashCode();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy