cassandra内部API使用三2010-07-07
/**根据Key从缓存删除缓存数据.
*
*@paramaKeyAreaKey
*/
publicvoidremove(StringaKeyArea)
{
CassandraClientPoolpool=CassandraClientPoolFactory.INSTANCE.get();
//取得客户端(群集服务器)
CassandraClientclient=null;
try
{
//从群集服务器获得一个客户端
client=pool.borrowClient(mCassandraClient);
//Keyspace
Keyspacekeyspace=
client.getKeyspace(mDefaultKeyspace);
//ColumnPath
ColumnPathcolumnPath=newColumnPath(mDefaultColumnFamily);
//从缓存中清除
keyspace.remove(aKeyArea,columnPath);
//为确保finally中能正确释放client,此处需重获取一次
client=keyspace.getClient();
}
catch(Exceptione)
{
sLog.error("根据Key从缓存删除缓存数据时出错。");
sLog.error(e);
}
finally
{
//finally中释放client
releaseClient(pool,client);
}
}
/**根据Key和column从缓存删除缓存数据.
*@paramaKeyAreaKey
*@paramaNamecolumn
*/
publicvoidremove(StringaKeyArea,StringaName)
{
CassandraClientPoolpool=CassandraClientPoolFactory.INSTANCE.get();
//取得客户端(群集服务器)
CassandraClientclient=null;
try
{
//从群集服务器获得一个客户端
client=pool.borrowClient(mCassandraClient);
//Keyspace
Keyspacekeyspace=
client.getKeyspace(mDefaultKeyspace);
//ColumnPath
ColumnPathcolumnPath=newColumnPath(mDefaultColumnFamily);
columnPath.setColumn(bytes(aName));
//从缓存中清除
keyspace.remove(aKeyArea,columnPath);
//为确保finally中能正确释放client,此处需重获取一次
client=keyspace.getClient();
}
catch(Exceptione)
{
sLog.error("根据Key和column从缓存删除缓存数据时出错。");
sLog.error(e);
}
finally
{
//finally中释放client
releaseClient(pool,client);
}
}