
org.geomajas.internal.service.DefaultCacheService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geomajas-impl Show documentation
Show all versions of geomajas-impl Show documentation
Geomajas server: Main - Implementation
The newest version!
/*
* This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
*
* Copyright 2008-2016 Geosparc nv, http://www.geosparc.com/, Belgium.
*
* The program is available in open source according to the GNU Affero
* General Public License. All contributions in this program are covered
* by the Geomajas Contributors License Agreement. For full licensing
* details, see LICENSE.txt in the project root.
*/
package org.geomajas.internal.service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.geomajas.service.CacheService;
import org.springframework.stereotype.Component;
/**
* Default implementation of the caches service that works in-memory. Note that this service does not distribute objects
* to different nodes in a load balancing environment.
*
* @author Oliver May
*
*/
@Component
public class DefaultCacheService implements CacheService {
private Map> caches = new ConcurrentHashMap>();
@Override
public void put(String cacheId, Object key, Object value) {
put(cacheId, key, value, DEFAULT_TTL);
}
@Override
public void put(String cacheId, Object key, Object value, long timeToLive) {
getOrCreateCache(cacheId).put(key, new CachedObject(value, System.currentTimeMillis() + timeToLive));
}
@Override
public Object get(String cacheId, Object key) {
CachedObject co = getOrCreateCache(cacheId).get(key);
return co != null ? co.getObject() : null;
}
@Override
public void cleanUp() {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy