Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
86557f25
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
86557f25
编写于
5月 30, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ConcurrentMapCacheManager recreates caches when initializing ClassLoader
Issue: SPR-14314
上级
cf0a0cd5
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
22 addition
and
11 deletion
+22
-11
spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java
.../springframework/cache/concurrent/ConcurrentMapCache.java
+5
-2
spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java
...framework/cache/concurrent/ConcurrentMapCacheManager.java
+17
-9
未找到文件。
spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java
浏览文件 @
86557f25
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -95,6 +95,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
* (adapting them to an internal null holder value)
* @param serialization the {@link SerializationDelegate} to use
* to serialize cache entry or {@code null} to store the reference
* @since 4.3
*/
protected
ConcurrentMapCache
(
String
name
,
ConcurrentMap
<
Object
,
Object
>
store
,
boolean
allowNullValues
,
SerializationDelegate
serialization
)
{
...
...
@@ -107,13 +108,15 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
this
.
serialization
=
serialization
;
}
/**
* Return whether this cache stores a copy of each entry ({@code true}) or
* a reference ({@code false}, default). If store by value is enabled, each
* entry in the cache must be serializable.
* @since 4.3
*/
public
final
boolean
isStoreByValue
()
{
return
this
.
serialization
!=
null
;
return
(
this
.
serialization
!=
null
)
;
}
@Override
...
...
spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheManager.java
浏览文件 @
86557f25
...
...
@@ -39,7 +39,7 @@ import org.springframework.core.serializer.support.SerializationDelegate;
* caching scenarios. For advanced local caching needs, consider
* {@link org.springframework.cache.jcache.JCacheCacheManager},
* {@link org.springframework.cache.ehcache.EhCacheCacheManager},
* {@link
com.github.benmanes.caffeine.cach
e.CaffeineCacheManager} or
* {@link
org.springframework.cache.caffein
e.CaffeineCacheManager} or
* {@link org.springframework.cache.guava.GuavaCacheManager}.
*
* @author Juergen Hoeller
...
...
@@ -106,9 +106,7 @@ public class ConcurrentMapCacheManager implements CacheManager, BeanClassLoaderA
if
(
allowNullValues
!=
this
.
allowNullValues
)
{
this
.
allowNullValues
=
allowNullValues
;
// Need to recreate all Cache instances with the new null-value configuration...
for
(
Map
.
Entry
<
String
,
Cache
>
entry
:
this
.
cacheMap
.
entrySet
())
{
entry
.
setValue
(
createConcurrentMapCache
(
entry
.
getKey
()));
}
recreateCaches
();
}
}
...
...
@@ -127,14 +125,13 @@ public class ConcurrentMapCacheManager implements CacheManager, BeanClassLoaderA
* contract is required on cached values.
* <p>Note: A change of the store-by-value setting will reset all existing caches,
* if any, to reconfigure them with the new store-by-value requirement.
* @since 4.3
*/
public
void
setStoreByValue
(
boolean
storeByValue
)
{
if
(
storeByValue
!=
this
.
storeByValue
)
{
this
.
storeByValue
=
storeByValue
;
// Need to recreate all Cache instances with the new store-by-value configuration...
for
(
Map
.
Entry
<
String
,
Cache
>
entry
:
this
.
cacheMap
.
entrySet
())
{
entry
.
setValue
(
createConcurrentMapCache
(
entry
.
getKey
()));
}
recreateCaches
();
}
}
...
...
@@ -142,6 +139,7 @@ public class ConcurrentMapCacheManager implements CacheManager, BeanClassLoaderA
* Return whether this cache manager stores a copy of each entry or
* a reference for all its caches. If store by value is enabled, any
* cache entry must be serializable.
* @since 4.3
*/
public
boolean
isStoreByValue
()
{
return
this
.
storeByValue
;
...
...
@@ -150,8 +148,13 @@ public class ConcurrentMapCacheManager implements CacheManager, BeanClassLoaderA
@Override
public
void
setBeanClassLoader
(
ClassLoader
classLoader
)
{
this
.
serialization
=
new
SerializationDelegate
(
classLoader
);
// Need to recreate all Cache instances with new ClassLoader in store-by-value mode...
if
(
isStoreByValue
())
{
recreateCaches
();
}
}
@Override
public
Collection
<
String
>
getCacheNames
()
{
return
Collections
.
unmodifiableSet
(
this
.
cacheMap
.
keySet
());
...
...
@@ -172,14 +175,19 @@ public class ConcurrentMapCacheManager implements CacheManager, BeanClassLoaderA
return
cache
;
}
private
void
recreateCaches
()
{
for
(
Map
.
Entry
<
String
,
Cache
>
entry
:
this
.
cacheMap
.
entrySet
())
{
entry
.
setValue
(
createConcurrentMapCache
(
entry
.
getKey
()));
}
}
/**
* Create a new ConcurrentMapCache instance for the specified cache name.
* @param name the name of the cache
* @return the ConcurrentMapCache (or a decorator thereof)
*/
protected
Cache
createConcurrentMapCache
(
String
name
)
{
SerializationDelegate
actualSerialization
=
this
.
storeByValue
?
this
.
serialization
:
null
;
SerializationDelegate
actualSerialization
=
(
isStoreByValue
()
?
this
.
serialization
:
null
);
return
new
ConcurrentMapCache
(
name
,
new
ConcurrentHashMap
<
Object
,
Object
>(
256
),
isAllowNullValues
(),
actualSerialization
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录