📄 cachekeyfactory.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.controller.cache;
import java.util.*;
import com.jdon.util.Debug;
/**
* 由于不能直接将数据ID作为Key保存到缓存中,因为可能ID数值重复,
* 因此必须将ID转换成CacheKey,再保存到缓存中。 *
* ID就是dataKey
*
* 子类:
* com.jdon.model.cache.ModelCacheKeyFactory
* com.jdon.model.query.PageCacheKeyFactory
*
* <p>Copyright: Jdon.com Copyright (c) 2003</p>
* <p></p>
* @author banq
* @version 1.0
*/
public abstract class CacheKeyFactory {
public final static String module = CacheKeyFactory.class.getName();
protected CacheFactory cacheFactory;
public CacheKeyFactory(CacheFactory cacheFactory){
this.cacheFactory = cacheFactory;
}
public CacheKey createCacheKey(Object dataKey, String typeName) {
CacheKey cacheKey = createCacheKeyImp(dataKey, typeName);
if (dataKey != null)
cacheFactory.getCacheKeyMap().put(cacheKey.toString(), dataKey.toString());
return cacheKey;
}
public abstract CacheKey createCacheKeyImp(Object dataKey, String typeName);
public void removeCacheKey(String cacheKeyStr){
cacheFactory.getCacheKeyMap().remove(cacheKeyStr);
}
/**
* 寻找所有与dataKey相关的CacheKey,宁多勿少。
* @param dataKey
* @return Collection
*/
public Collection getAllCacheKey(Object dataKey){
String cacheKey = null;
String dataTmpKey = null;
Collection list = new ArrayList();
Map map = cacheFactory.getCacheKeyMap();
Iterator iter = map.keySet().iterator();
while(iter.hasNext()){
cacheKey = (String)iter.next();
dataTmpKey = (String)map.get(cacheKey);
if (dataTmpKey.equals(dataKey)){
list.add(cacheKey);
}
}
return list;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -