网站建设价格标准案例,WordPress推送服务,石家庄网站建设电话,百度百科怎么创建mybatis缓存二级缓存一周前#xff0c;MyBatis和Apache ignite 宣布支持apache ignite作为MyBatis缓存#xff08;L2缓存#xff09;。 从技术上讲#xff0c;MyBatis支持两个级别的缓存#xff1a; 本地缓存#xff0c;默认情况下始终启用 L2缓存#xff0c;可选 随… mybatis缓存二级缓存 一周前MyBatis和Apache ignite 宣布支持apache ignite作为MyBatis缓存L2缓存。 从技术上讲MyBatis支持两个级别的缓存 本地缓存默认情况下始终启用 L2缓存可选 随着Apache Ignite项目的各种功能Swift发展在本博客中我们将详细研究MyBatis支持。 第二级缓存存储实体数据但不存储实体或对象本身。 数据以“序列化”格式存储看起来像哈希图其中键是实体ID而值是原始值列表。 这是一个示例其缓存条目在Apache ignite中的样子 哪里 快取金钥 CacheKey [idHash1499858, hash2019660929, checksum800710994, count6, multiplier37, hashcode2019660929, updateList[com.blu.ignite.mapper.UserMapper.getUserObject, 0, 2147483647, SELECT * FROM all_objects t where t.OBJECT_TYPETABLE and t.object_name?, USERS, SqlSessionFactoryBean]] 值类 java.util.ArrayList 缓存值 [UserObject [idHash243119413, hash1658511469, ownerC##DONOTDELETE, object_typeTABLE, object_id94087, createdMon Feb 15 13:59:41 MSK 2016, object_nameUSERS]] 对于示例我从Oracle数据库中选择了“ all_objects”对象和以下查询 SELECT count(*) FROM all_objects;SELECT * FROM all_objects t where t.OBJECT_TYPETABLE and t.object_nameEMP;SELECT * FROM all_objects t where t.OBJECT_TYPETABLE; 就我而言给定的查询执行时间平均约为660毫秒。 SELECT count(*) FROM all_objects; 接下来的查询执行时间超过700ms SELECT t.object_type, count(*) FROM all_objects t group by t.OBJECT_TYPE; 让我们添加apache ignite作为第二级缓存并检查结果。 如果您想知道如何使用spring和myBatis安装和配置apache ignite请参阅我以前的博客文章 。 此外您可以在github存储库中找到所有源代码。 作为快速入门让我们在项目中添加myBatis maven依赖项。 dependencygroupIdorg.mybatis.caches/groupIdartifactIdmybatis-ignite/artifactIdversion1.0.0-beta1/version
/dependency 然后只需在映射器XML中指定它如下所示 mapper namespacecom.blu.ignite.mapper.UserMappercache typeorg.mybatis.caches.ignite.IgniteCacheAdapter /select idgetUserObject parameterTypeString resultTypecom.blu.ignite.dto.UserObject useCachetrueSELECT * FROM all_objects t where t.OBJECT_TYPETABLE and t.object_name#{objectName}/selectselect idgetAllObjectsTypeByGroup parameterTypeString resultTypecom.blu.ignite.dto.UobjectGroupBy useCachetrueSELECT t.object_type, count(*) as cnt FROM all_objects t group by t.OBJECT_TYPE/selectselect idallObjectCount parameterTypeString resultTypeString useCachetrueSELECT count(*) FROM all_objects/select
/mapper 我也有以下的Java映射器 public interface UserMapper {User getUser( String id);List getUniqueJob();UserObject getUserObject(String objectName);String allObjectCount();List getAllObjectsTypeByGroup();
} 和Web服务如下所示 WebService(name BusinessRulesServices,serviceNameBusinessRulesServices,targetNamespace http://com.blu.rules/services)
public class WebServices {private UserServices userServices;WebMethod(operationName getUserName)public String getUserName(String userId){User user userServices.getUser(userId);return user.getuName();}WebMethod(operationName getUserObject)public UserObject getUserObject(String objectName){return userServices.getUserObject(objectName);}WebMethod(operationName getUniqueJobs)public List getUniqueJobs(){return userServices.getUniqueJobs();}WebMethod(exclude true)public void setDao(UserServices userServices){this.userServices userServices;}WebMethod(operationName allObjectCount)public String allObjectCount(){return userServices.allObjectCount();}WebMethod(operationName getAllObjectsTypeCntByGroup)public List getAllObjectsTypeCntByGroup(){return userServices.getAllObjectCntbyGroup();}} 如果我将在soupUI中调用Web方法“ getAllObjectsTypeCntByGroup”则第一次它将获得非常高的响应时间大约为1700 ms因为结果不在缓存中。 从第二次开始响应时间将为〜4到〜5 ms。 首次调用网络方法如下所示 第二次或更晚调用Web方法的响应时间 在apache中ignite缓存条目将如下所示 快取金钥 CacheKey [idHash46158416, hash1558187086, checksum2921583030, count5, multiplier37, hashcode1558187086, updateList[com.blu.ignite.mapper.UserMapper.getAllObjectsTypeByGroup, 0, 2147483647, SELECT t.object_type, count(*) as cnt FROM all_objects t group by t.OBJECT_TYPE, SqlSessionFactoryBean]] 值类 java.util.ArrayList 缓存值 [UobjectGroupBy [idHash2103707742, hash1378996400, cnt1, object_typeEDITION], UobjectGroupBy [idHash333378159, hash872886462, cnt444, object_typeINDEX PARTITION], UobjectGroupBy [idHash756814918, hash1462794064, cnt32, object_typeTABLE SUBPARTITION], UobjectGroupBy [idHash931078572, hash953621437, cnt2, object_typeCONSUMER GROUP], UobjectGroupBy [idHash1778706917, hash1681913927, cnt256, object_typeSEQUENCE], UobjectGroupBy [idHash246231872, hash1764800190, cnt519, object_typeTABLE PARTITION], UobjectGroupBy [idHash1138665719, hash1030673983, cnt4, object_typeSCHEDULE], UobjectGroupBy [idHash232948577, hash1038362844, cnt1, object_typeRULE], UobjectGroupBy [idHash1080301817, hash646054631, cnt310, object_typeJAVA DATA], UobjectGroupBy [idHash657724550, hash1248576975, cnt201, object_typePROCEDURE], UobjectGroupBy [idHash295410055, hash33504659, cnt54, object_typeOPERATOR], UobjectGroupBy [idHash150727006, hash499210168, cnt2, object_typeDESTINATION], UobjectGroupBy [idHash1865360077, hash727903197, cnt9, object_typeWINDOW], UobjectGroupBy [idHash582342926, hash1060308675, cnt4, object_typeSCHEDULER GROUP], UobjectGroupBy [idHash1968399647, hash1205380883, cnt1306, object_typePACKAGE], UobjectGroupBy [idHash1495061270, hash1345537223, cnt1245, object_typePACKAGE BODY], UobjectGroupBy [idHash1328790450, hash1823695135, cnt228, object_typeLIBRARY], UobjectGroupBy [idHash1128429299, hash1267824468, cnt10, object_typePROGRAM], UobjectGroupBy [idHash760711193, hash1240703242, cnt17, object_typeRULE SET], UobjectGroupBy [idHash317487814, hash61657487, cnt10, object_typeCONTEXT], UobjectGroupBy [idHash1079028994, hash1960895356, cnt229, object_typeTYPE BODY], UobjectGroupBy [idHash276147733, hash873140579, cnt44, object_typeXML SCHEMA], UobjectGroupBy [idHash24378178, hash1621363993, cnt1014, object_typeJAVA RESOURCE], UobjectGroupBy [idHash1891142624, hash90282027, cnt10, object_typeDIRECTORY], UobjectGroupBy [idHash902107208, hash1995006200, cnt593, object_typeTRIGGER], UobjectGroupBy [idHash142411235, hash444983119, cnt14, object_typeJOB CLASS], UobjectGroupBy [idHash373966405, hash1518992835, cnt3494, object_typeINDEX], UobjectGroupBy [idHash580466919, hash1394644601, cnt2422, object_typeTABLE], UobjectGroupBy [idHash1061370796, hash1861472837, cnt37082, object_typeSYNONYM], UobjectGroupBy [idHash1609659322, hash1543110475, cnt6487, object_typeVIEW], UobjectGroupBy [idHash458063471, hash1317758482, cnt346, object_typeFUNCTION], UobjectGroupBy [idHash1886921697, hash424653540, cnt7, object_typeINDEXTYPE], UobjectGroupBy [idHash1455482905, hash1776171634, cnt30816, object_typeJAVA CLASS], UobjectGroupBy [idHash49819096, hash2110362533, cnt2, object_typeJAVA SOURCE], UobjectGroupBy [idHash1916179950, hash1760023032, cnt10, object_typeCLUSTER], UobjectGroupBy [idHash1138808674, hash215713426, cnt2536, object_typeTYPE], UobjectGroupBy [idHash305229607, hash340664529, cnt23, object_typeJOB], UobjectGroupBy [idHash1365509716, hash623631686, cnt12, object_typeEVALUATION CONTEXT]] 结论 使用L2缓存可以减少昂贵的数据库操作在MyBatis中正确使用L2缓存可以将应用程序性能提高10到20倍。 内存数据网格中的Apache Ignite非常适合用于此目的当然您也可以使用HazelcashEhCache或任何其他缓存工具。 翻译自: https://www.javacodegeeks.com/2016/03/pitfalls-mybatis-caches-apache-ignite.htmlmybatis缓存二级缓存