-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve cache initialization in CacheManager.
- Loading branch information
Showing
7 changed files
with
65 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import com.alicp.jetcache.anno.support.ConfigMap; | ||
import org.springframework.aop.Pointcut; | ||
import org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">huangli</a> | ||
|
@@ -14,6 +15,7 @@ public class CacheAdvisor extends AbstractBeanFactoryPointcutAdvisor { | |
|
||
public static final String CACHE_ADVISOR_BEAN_NAME = "jetcache2.internalCacheAdvisor"; | ||
|
||
@Autowired | ||
private ConfigMap cacheConfigMap; | ||
|
||
private String[] basePackages; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.function.BiFunction; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">huangli</a> | ||
|
@@ -17,6 +18,7 @@ public class SimpleCacheManager implements CacheManager { | |
private static final Logger logger = LoggerFactory.getLogger(SimpleCacheManager.class); | ||
|
||
private ConcurrentHashMap<String, ConcurrentHashMap<String, Cache>> caches = new ConcurrentHashMap<>(); | ||
private BiFunction<String, String, Cache> cacheCreator; | ||
|
||
static SimpleCacheManager defaultManager = new SimpleCacheManager(); | ||
|
||
|
@@ -42,6 +44,16 @@ private ConcurrentHashMap<String, Cache> getCachesByArea(String area) { | |
|
||
@Override | ||
public Cache getCache(String area, String cacheName) { | ||
ConcurrentHashMap<String, Cache> areaMap = getCachesByArea(area); | ||
Cache c = areaMap.get(cacheName); | ||
if (c == null && cacheCreator != null) { | ||
return cacheCreator.apply(area, cacheName); | ||
} else { | ||
return c; | ||
} | ||
} | ||
|
||
public Cache getCacheWithoutCreate(String area, String cacheName) { | ||
ConcurrentHashMap<String, Cache> areaMap = getCachesByArea(area); | ||
return areaMap.get(cacheName); | ||
} | ||
|
@@ -50,4 +62,8 @@ public void putCache(String area, String cacheName, Cache cache) { | |
ConcurrentHashMap<String, Cache> areaMap = getCachesByArea(area); | ||
areaMap.put(cacheName, cache); | ||
} | ||
|
||
public void setCacheCreator(BiFunction<String, String, Cache> cacheCreator) { | ||
this.cacheCreator = cacheCreator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters