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

com.tsc9526.monalisa.tools.cache.TransactionalCacheManager Maven / Gradle / Ivy

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

import java.util.HashMap;
import java.util.Map;

import com.tsc9526.monalisa.tools.cache.decorators.TransactionalCache;

public class TransactionalCacheManager {

	private Map transactionalCaches = new HashMap();

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

	public void putObject(Cache cache, CacheKey key, Object value,long ttlInSeconds) {
		getTransactionalCache(cache).putObject(key, value,ttlInSeconds);
	}
	
	public Object getObject(Cache cache, CacheKey key) {
		return getTransactionalCache(cache).getObject(key);
	}

	public void commit() {
		for (TransactionalCache txCache : transactionalCaches.values()) {
			txCache.commit();
		}
	}

	public void rollback() {
		for (TransactionalCache txCache : transactionalCaches.values()) {
			txCache.rollback();
		}
	}

	private TransactionalCache getTransactionalCache(Cache cache) {
		TransactionalCache txCache = transactionalCaches.get(cache);
		if (txCache == null) {
			txCache = new TransactionalCache(cache);
			transactionalCaches.put(cache, txCache);
		}
		return txCache;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy