1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package com.yiidata.intergration.web.modules.sys.cache;
- import com.google.common.collect.ImmutableSet;
- import org.springframework.cache.Cache;
- import org.springframework.cache.CacheManager;
- import org.springframework.stereotype.Component;
- import javax.annotation.Resource;
- import java.util.Collection;
- import java.util.HashSet;
- import java.util.Set;
- /**
- *
- * 支持缓存, @Cacheable 注解。
- *
- * CAcheManager 无须自己 shutdown,创建 该 Cache 的 Factory 在销毁是会 shutdown
- *
- * <pre>
- *
- * User: zhenqin
- * Date: 14/11/9
- * Time: 10:43
- *
- * </pre>
- *
- * @author zhenqin
- */
- @Component("cacheManager")
- public class ICacheManager implements CacheManager {
- /**
- * 支持 cacheManager 的缓存
- */
- @Resource
- private ICache cache;
- /**
- * 已经获得的缓存
- */
- private Set<String> cacheNames = new HashSet<>();
- /**
- * Construct a dynamic ICacheManager,
- * lazily creating cache instances as they are being requested.
- */
- public ICacheManager() {
- }
- /**
- * 支持的 缓存 名称
- * @return
- */
- @Override
- public Collection<String> getCacheNames() {
- return ImmutableSet.copyOf(cacheNames);
- }
- @Override
- public Cache getCache(String name) {
- if(!cacheNames.contains(name)) {
- // 如果 cacheNames 中没有,说明是新建的
- cacheNames.add(name);
- }
- return new ProxyCache(cache);
- }
- public void setCache(ICache cache) {
- this.cache = cache;
- }
- }
|