net.ymate.platform.cache.Caches Maven / Gradle / Ivy
/*
* Copyright 2007-2017 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 net.ymate.platform.cache;
import net.ymate.platform.cache.impl.DefaultCacheProvider;
import net.ymate.platform.cache.impl.DefaultModuleCfg;
import net.ymate.platform.cache.impl.MultilevelCacheProvider;
import net.ymate.platform.cache.impl.RedisCacheProvider;
import net.ymate.platform.core.Version;
import net.ymate.platform.core.YMP;
import net.ymate.platform.core.module.IModule;
import net.ymate.platform.core.module.annotation.Module;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 缓存管理器
*
* @author 刘镇 ([email protected]) on 14-10-16
* @version 1.0
*/
@Module
public class Caches implements IModule, ICaches {
public static final Version VERSION = new Version(2, 0, 2, Caches.class.getPackage().getImplementationVersion(), Version.VersionType.Release);
private static final Log _LOG = LogFactory.getLog(Caches.class);
private static volatile ICaches __instance;
private YMP __owner;
private ICacheModuleCfg __moduleCfg;
private ICacheProvider __cacheProvider;
private boolean __inited;
/**
* @return 返回默认缓存模块管理器实例对象
*/
public static ICaches get() {
if (__instance == null) {
synchronized (VERSION) {
if (__instance == null) {
__instance = YMP.get().getModule(Caches.class);
}
}
}
return __instance;
}
/**
* @param owner YMP框架管理器实例
* @return 返回指定YMP框架管理器容器内的缓存模块实例
*/
public static ICaches get(YMP owner) {
return owner.getModule(Caches.class);
}
public String getName() {
return ICaches.MODULE_NAME;
}
public void init(YMP owner) throws Exception {
if (!__inited) {
//
_LOG.info("Initializing ymate-platform-cache-" + VERSION);
//
__owner = owner;
__moduleCfg = new DefaultModuleCfg(owner);
__cacheProvider = __moduleCfg.getCacheProvider();
__cacheProvider.init(this);
//
__inited = true;
}
}
public boolean isInited() {
return __inited;
}
public YMP getOwner() {
return __owner;
}
public ICacheModuleCfg getModuleCfg() {
return __moduleCfg;
}
public ICacheProvider getCacheProvider() {
return __cacheProvider;
}
public Object get(String cacheName, Object key) {
ICache _cache = __cacheProvider.getCache(cacheName);
if (_cache != null) {
return _cache.get(key);
}
return null;
}
public Object get(Object key) {
return get(__moduleCfg.getDefaultCacheName(), key);
}
public Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy