mybatisplus 二级缓存

来源:互联网 发布:网络销售高仿酒 编辑:程序博客网 时间:2024/05/28 17:08

1将mybatisplus的全局配置的cache-enabled配置为true

mybatis-plus:  dataSource: datasource  mapper-locations: classpath:/mapper/*/*Mapper.xml  typeAliasesPackage: com.wbst.modules.*.entity  global-config:    id-type: 2    field-strategy: 2    db-column-underline: true    refresh-mapper: true    configuration:      map-underscore-to-camel-case: true      cache-enabled: true

2在需要配置二级缓存的mapper映射文件如:test.xml加入如下配置:

<cache eviction="FIFO"
flushInterval="10800000"
size="512"
readOnly="true"
/>

这个最好写在开头位置,一般第一条查询语句前面的可以了
3有些select不想被缓存时,可以添加select的属性useCache=“false”
4将查询结果对应的java实体类实现序列化接口(implements Serializable)