代码拉取完成,页面将自动刷新
Kache-Spring - 散列式缓存 Spring自动配置版
1.pom文件引入:
<dependency>
<groupId>io.gitee.kroup</groupId>
<artifactId>Kache-Spring</artifactId>
<version>1.0.1.INFORMAL_VERSION</version>
</dependency>
2.缓存实体继承KacheEntity接口
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("kork_article")
public class Article extends BasePO implements KacheEntity {
private static final long serialVersionUID = -4470366380115322213L;
@DataFactory(minLen = 10)
private String title;
private String summary;
@JsonAdapter(IdAdapter.class)
private Long authorId;
@JsonAdapter(IdAdapter.class)
private Long bodyId;
@JsonAdapter(IdAdapter.class)
private Long categoryId;
private Integer commentCounts;
private Long viewCounts;
private ArticleType weight;
@Override
public String getPrimaryKey() {
return getId().toString();
}
}
3.其对应的Dao层的Mapper以及Dao方法添加注释:
@Repository
// 自动注册代理注解
@CacheEntity(Article.class)
public interface TagMapper extends BaseMapper<Tag> {
@Select("select t.* from klog_article_tag at "
+ "right join klog_tag t on t.id = at.tag_id "
+ "where t.deleted = 0 AND at.deleted = 0 "
+ "group by t.id order by count(at.tag_id) desc limit #{limit}")
@DaoMethod(value = Type.SELECT,status = Status.BY_FIELD)
// 通过条件查询获取数据
List<Tag> listHotTagsByArticleUse(@Param("limit") int limit);
@DaoMethod(Type.INSERT)
// 批量新增方法(会导致数据变动)
Integer insertBatch(Collection<T> entityList);
}
4.注册PageDetails对象
构造参数:
分页对象Class:Page.class
实体数据集合属性名:“records”
实体数据集合属性Class:List.class
@Configuration
public class KacheConfig {
@Bean
public PageDetails<Page> pageDetails() throws NoSuchFieldException, IllegalAccessException {
return new PageDetails<>(Page.class, "records", List.class);
}
}
自定义配置或组件:
// 以接口类型作为键值替换默认配置或增加额外配置
// 用于配置或组件加载
load(Class<?> interfaceClass, Object bean);
// 示例:使用Kache默认提供的额外AMQP异步删改策略实现
@Bean
public Kache kache() {
return Kache.builder()
// 新增Connection接口配置,并提供接口实例
.load(Connection.class, factory.newConnection())
.build();
}
application.yml参考配置
#Kache application.yml对应属性值
kache:
dao:
base-time: 86400 // 缓存基本存活时间
random-time: 600 // 缓存随机延长时间
poolMaxTotal: 20 // Redis连接池最大连接数
poolMaxIdle: 5 // Redis连接池最大Idle状态连接数
casKeepTime: 1 // 幂等cas凭证删除时间
local-cache:
enable: true // 进程间缓存是否开启
size: 50 // 进程间缓存数量
listener:
enable: true // 监听器是否开启
method-key: // dao方法名匹配(适用于无法添加注释情况)
selectKey: "select"
insertKey: "insert"
deleteKey: "delete"
updateKey: "update"
selectByIdKey: "selectById"
insertByIdKey: "insertById"
updateByIdKey: "updateById"
deleteByIdKey: "deleteById"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。