添加适配度排序
This commit is contained in:
@@ -30,9 +30,15 @@ public class CacheConfig {
|
||||
/** 缓存名:热门城市 */
|
||||
public static final String HOT_CITY = "hotCity";
|
||||
|
||||
/** 缓存名:岗位匹配度排序结果(单条目为5000个JobDto,占用大,容量单独控制) */
|
||||
public static final String JOB_MATCH_SORT = "jobMatchSort";
|
||||
|
||||
/** 单个缓存最大条目数 */
|
||||
private static final long MAX_SIZE = 100;
|
||||
|
||||
/** 岗位匹配度排序缓存最大条目数(单条目约5~10MB,不能按 MAX_SIZE 放开) */
|
||||
private static final long JOB_MATCH_SORT_MAX_SIZE = 20;
|
||||
|
||||
/**
|
||||
* 缓存管理器
|
||||
* <p>三个热门榜单各注册一份独立的 Caffeine 实例,过期时间互相独立(单位:分钟)</p>
|
||||
@@ -48,22 +54,26 @@ public class CacheConfig {
|
||||
.maximumSize(MAX_SIZE));
|
||||
|
||||
// 各缓存独立注册,独立过期时间
|
||||
cacheManager.registerCustomCache(HOT_INDUSTRY, buildCache(60));
|
||||
cacheManager.registerCustomCache(HOT_JOB_CATEGORY, buildCache(60));
|
||||
cacheManager.registerCustomCache(HOT_CITY, buildCache(60));
|
||||
cacheManager.registerCustomCache(HOT_INDUSTRY, buildCache(60, MAX_SIZE));
|
||||
cacheManager.registerCustomCache(HOT_JOB_CATEGORY, buildCache(60, MAX_SIZE));
|
||||
cacheManager.registerCustomCache(HOT_CITY, buildCache(60, MAX_SIZE));
|
||||
|
||||
// 匹配度排序结果:单条目占用大,容量收紧;内含收藏/投递状态快照,时长不宜过长
|
||||
cacheManager.registerCustomCache(JOB_MATCH_SORT, buildCache(5, JOB_MATCH_SORT_MAX_SIZE));
|
||||
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建一个指定过期时长的 Caffeine 缓存实例
|
||||
* 构建一个 Caffeine 缓存实例
|
||||
*
|
||||
* @param expireMinutes 写入后过期时长(分钟)
|
||||
* @param maximumSize 最大条目数
|
||||
*/
|
||||
private Cache<Object, Object> buildCache(long expireMinutes) {
|
||||
private Cache<Object, Object> buildCache(long expireMinutes, long maximumSize) {
|
||||
return Caffeine.newBuilder()
|
||||
.expireAfterWrite(expireMinutes, TimeUnit.MINUTES)
|
||||
.maximumSize(MAX_SIZE)
|
||||
.maximumSize(maximumSize)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user