📄 modelcachemanager.java
字号:
/**
* Copyright 2005 Jdon.com
* 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 com.jdon.model.cache;
import java.util.*;
import com.jdon.util.Debug;
import com.jdon.controller.model.Model;
import com.jdon.controller.cache.CacheFactory;
import com.jdon.controller.cache.CacheKey;
import com.jdon.controller.cache.CacheKeyFactory;
import com.jdon.model.mapping.ModelMapping;
import com.jdon.model.config.ModelXmlConfig;
public class ModelCacheManager implements org.picocontainer.Startable{
private final static String module = ModelCacheManager.class.getName();
protected CacheFactory cacheFactory;
private CacheKeyFactory cacheKeyFactory;
private ModelXmlConfig modelFactory;
public ModelCacheManager(ModelXmlConfig modelFactory, CacheFactory cacheFactory) {
this.cacheFactory = cacheFactory;
this.modelFactory = modelFactory;
this.cacheKeyFactory = new ModelCacheKeyFactory(cacheFactory);
}
public void start() {
Debug.logVerbose("ModelCacheManager start ...", module);
}
public void stop() {
}
/**
* 将数据ID, Form名称组合成Key, 将对应的Model保存到缓存
*
* 基于一个Form名称对应一个Model类型
*
* @param dataKey
* @param formName
* @param model
*/
public void setCache(Object dataKey, String formName, Model model) {
CacheKey cachKey = getCacheKey(dataKey, formName);
if ( (model.isCacheble()) && (model != null)) { //保存到缓存中
cacheFactory.putObect(cachKey, model);
}
}
/**
* 将数据ID, Model类类型组合成Key, 将对应的Model保存到缓存
* @param dataKey
* @param modelClassName
* @param model
*/
public void setCache2(Object dataKey, String modelClassName, Model model) {
CacheKey cachKey = getCacheKey2(dataKey, modelClassName);
if ( (model.isCacheble()) && (model != null)) { //保存到缓存中
cacheFactory.putObect(cachKey, model);
}
}
/**
* 将数据ID, Form名称组合成Key的对应Model从缓存中取出
*
* 基于一个Form名称对应一个Model类型
* @param dataKey
* @param formName
* @return
*/
public Model getCache(Object dataKey, String formName) {
CacheKey cachKey = getCacheKey(dataKey, formName);
if (cachKey != null)
return (Model) cacheFactory.getObect(cachKey);
else
return null;
}
/**
* 将数据ID, Model类类型组合成Key的对应Model从缓存中取出
* @param dataKey
* @param modelClassName
* @return
*/
public Model getCache2(Object dataKey, String modelClassName) {
CacheKey cachKey = getCacheKey2(dataKey, modelClassName);
if (cachKey != null)
return (Model) cacheFactory.getObect(cachKey);
else
return null;
}
/**
* 清除缓存中该dataKey的相关所有缓存数据
* dataKey即数据的主键ID数值
*
* @param dataKey
* @param formName
*/
public void removeCache(Object dataKey) {
cacheFactory.removeCache(dataKey, cacheKeyFactory);
}
/**
* 将数据ID, Model类类型组合成Key的对应Model从缓存中取出
* @param dataKey
* @param modelClassName
* @return
*/
public void removeCache2(Object dataKey, String modelClassName) {
CacheKey cachKey = getCacheKey2(dataKey, modelClassName);
if (cachKey != null)
cacheFactory.removeObect(cachKey);
}
/**
* 生成缓存中保存Model的Key,根据ActionForm名称
* @param dataKey
* @param formName
* @return String
*/
public CacheKey getCacheKey(Object dataKey, String formName) {
ModelMapping modelMapping = this.modelFactory.getModelMapping(formName);
return cacheKeyFactory.createCacheKey(dataKey, modelMapping.getClassName());
}
public CacheKey getCacheKey2(Object dataKey, String modelClassName) {
return cacheKeyFactory.createCacheKey(dataKey, modelClassName);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -