Search in sources :

Example 1 with RefreshCache

use of com.alicp.jetcache.RefreshCache in project jetcache by alibaba.

the class CacheContext method buildCache.

protected Cache buildCache(CacheAnnoConfig cacheAnnoConfig, String area, String fullCacheName) {
    Cache cache;
    if (cacheAnnoConfig.getCacheType() == CacheType.LOCAL) {
        cache = buildLocal(cacheAnnoConfig, area);
    } else if (cacheAnnoConfig.getCacheType() == CacheType.REMOTE) {
        cache = buildRemote(cacheAnnoConfig, area, fullCacheName);
    } else {
        Cache local = buildLocal(cacheAnnoConfig, area);
        Cache remote = buildRemote(cacheAnnoConfig, area, fullCacheName);
        if (defaultCacheMonitorManager != null) {
            DefaultCacheMonitor localMonitor = new DefaultCacheMonitor(fullCacheName + "_local");
            local.config().getMonitors().add(localMonitor);
            DefaultCacheMonitor remoteMonitor = new DefaultCacheMonitor(fullCacheName + "_remote");
            remote.config().getMonitors().add(remoteMonitor);
            defaultCacheMonitorManager.add(localMonitor, remoteMonitor);
        }
        cache = MultiLevelCacheBuilder.createMultiLevelCacheBuilder().expireAfterWrite(local.config().getExpireAfterWriteInMillis(), TimeUnit.MILLISECONDS).addCache(local, remote).buildCache();
    }
    cache = new RefreshCache(cache);
    if (defaultCacheMonitorManager != null) {
        DefaultCacheMonitor monitor = new DefaultCacheMonitor(fullCacheName);
        cache.config().getMonitors().add(monitor);
        defaultCacheMonitorManager.add(monitor);
    }
    return cache;
}
Also used : RefreshCache(com.alicp.jetcache.RefreshCache) DefaultCacheMonitor(com.alicp.jetcache.support.DefaultCacheMonitor) RefreshCache(com.alicp.jetcache.RefreshCache) Cache(com.alicp.jetcache.Cache) EnableCache(com.alicp.jetcache.anno.EnableCache)

Aggregations

Cache (com.alicp.jetcache.Cache)1 RefreshCache (com.alicp.jetcache.RefreshCache)1 EnableCache (com.alicp.jetcache.anno.EnableCache)1 DefaultCacheMonitor (com.alicp.jetcache.support.DefaultCacheMonitor)1