cassandra外部使用示例一
packagecom.huawei.support.navigation.dao;
importjava.io.Serializable;
importjava.lang.reflect.Method;
importjava.util.HashMap;
importjava.util.List;
importjava.util.Map;
importorg.apache.commons.logging.Log;
importorg.apache.commons.logging.LogFactory;
importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.beans.factory.annotation.Qualifier;
importorg.springframework.stereotype.Service;
importcom.huawei.support.cache.ICassCache;
importcom.huawei.support.cache.impl.CacheConfigReader;
importcom.huawei.support.cache.impl.CassCache;
importcom.huawei.support.exception.ApplicationException;
@Service("navigationDaoCache")
publicclassNavigationDaoCache
{
privatestaticLogsLog=LogFactory.getLog(CassCache.class);
privatefinalstaticStringCACHE_FUNCTION="support.navigation.navigationdaocache";
privatefinalstaticStringNODE_DOC_LIST=".node_doc_list";
privatefinalstaticStringNAVIGATOIN_CACHE="navigationCache";
privatebooleanIS_USE_CACHE=true;
privatefinalstaticlongCACHE_LIFE_CYCLE=10*60*1000;
@Autowired
@Qualifier("navigationDao")
privateNavigationDaonavigationDao;
@Autowired
@Qualifier("cassCache")
privateICassCachecache;
publicNavigationDaoCache()throwsApplicationException
{
//从配置文件中读取是否使用缓存的配置
IS_USE_CACHE=Boolean.parseBoolean(CacheConfigReader.getInstance()
.getPropertyFromBinding(NAVIGATOIN_CACHE));
}
/**
*清除缓存对象数据
*/
publicvoidclearCache()throwsApplicationException
{
try
{
Classc=this.getClass();
Method[]methods=c.getMethods();
for(inti=0;i<methods.length;i++)
{
Methodmethod=methods[i];
StringmethodStr=methods[i].getName();
if(method.getModifiers()==1&&methodStr.startsWith("get"))
{
StringcacheAreaName=CACHE_FUNCTION+"."+methodStr;
cache.remove(cacheAreaName);
}
}
}
catch(Exceptione)
{
e.printStackTrace();
thrownewApplicationException("clearCacheerror",e);
}
}