org.springframework.cache.concurrent.ConcurrentMapCache Maven / Gradle / Ivy
Show all versions of spring-context Show documentation
/*
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache.concurrent;
import java.io.Serializable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.springframework.cache.Cache;
import org.springframework.cache.support.SimpleValueWrapper;
import org.springframework.util.Assert;
/**
* Simple {@link Cache} implementation based on the core JDK
* {@code java.util.concurrent} package.
*
* Useful for testing or simple caching scenarios, typically in combination
* with {@link org.springframework.cache.support.SimpleCacheManager} or
* dynamically through {@link ConcurrentMapCacheManager}.
*
*
Note: As {@link ConcurrentHashMap} (the default implementation used)
* does not allow for {@code null} values to be stored, this class will replace
* them with a predefined internal object. This behavior can be changed through the
* {@link #ConcurrentMapCache(String, ConcurrentMap, boolean)} constructor.
*
* @author Costin Leau
* @author Juergen Hoeller
* @since 3.1
*/
public class ConcurrentMapCache implements Cache {
private static final Object NULL_HOLDER = new NullHolder();
private final String name;
private final ConcurrentMap