|
@@ -1,8 +1,11 @@
|
|
|
package com.tzld.piaoquan.recommend.server.service;
|
|
|
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
import com.tzld.piaoquan.recommend.server.model.Video;
|
|
|
+import com.tzld.piaoquan.recommend.server.util.CommonCollectionUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -13,10 +16,7 @@ import org.springframework.data.redis.core.ScanOptions;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
@@ -29,6 +29,9 @@ public class PreViewedService {
|
|
|
@Qualifier("redisTemplate")
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
+ @ApolloJsonValue("${preview.exp.config:{}}")
|
|
|
+ private Map<String, Integer> preViewExpConfig;
|
|
|
+
|
|
|
public static final String KEY_PRE_VIEWED_FORMAT = "previewed:videos:%s:%s";
|
|
|
|
|
|
// private LoadingCache<String, Set<Long>> preViewedCache = CacheBuilder.newBuilder()
|
|
@@ -43,7 +46,7 @@ public class PreViewedService {
|
|
|
// }
|
|
|
// });
|
|
|
|
|
|
- public void updateCache(int appType, String mid, List<Video> videos) {
|
|
|
+ public void updateCache(int appType, String mid, List<Video> videos, Set<String> abExpCodes) {
|
|
|
if (StringUtils.isBlank(mid)
|
|
|
|| CollectionUtils.isEmpty(videos)) {
|
|
|
return;
|
|
@@ -54,8 +57,21 @@ public class PreViewedService {
|
|
|
videoIds[i] = String.valueOf(videos.get(i).getVideoId());
|
|
|
}
|
|
|
String key = String.format(KEY_PRE_VIEWED_FORMAT, appType, mid);
|
|
|
+
|
|
|
+ int expire = 30;
|
|
|
+ if (MapUtils.isNotEmpty(preViewExpConfig)) {
|
|
|
+ for (Map.Entry<String, Integer> entry : preViewExpConfig.entrySet()) {
|
|
|
+ if (CommonCollectionUtils.contains(abExpCodes, entry.getKey())) {
|
|
|
+ expire = entry.getValue() != null
|
|
|
+ ? entry.getValue()
|
|
|
+ : 30;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
redisTemplate.opsForSet().add(key, videoIds);
|
|
|
- redisTemplate.expire(key, 30, TimeUnit.MINUTES);
|
|
|
+ redisTemplate.expire(key, expire, TimeUnit.MINUTES);
|
|
|
}
|
|
|
|
|
|
public Set<Long> getVideoIds(int appType, String mid) {
|