guava缓存
来源:互联网 发布:海信电视看电影软件 编辑:程序博客网 时间:2024/05/23 01:57
private LoadingCache<Integer, List<Long>> topAdvertListCache = CacheBuilder.newBuilder()
.maximumSize(1000)
.refreshAfterWrite(60, TimeUnit.SECONDS)
.build(
new CacheLoader<Integer, List<Long>>() {
public List<Long> load(Integer key) {
return getTopAdvertFromEs(key);
}
public ListenableFutureTask<List<Long>> reload(final Integer key, List<Long> prevGraph) {
ListenableFutureTask<List<Long>> task = ListenableFutureTask.create(() -> getTopAdvertFromEs(key));
Executors.newSingleThreadExecutor().execute(task);
return task;
}
});
private List<Long> getTopAdvertFromEs(Integer key) {
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(matchAllQuery())
.withSearchType(SearchType.DEFAULT)
.withIndices(couponLogEsConfig.getIndexPrefix() + "-" + getYesterdayDate()).withTypes(couponLogEsConfig.getTypeName())
.addAggregation(terms("AppId").field("appId").size(0))
.build();
Aggregations aggregations = esTemplate.query(searchQuery, response -> response.getAggregations());
Terms byApp = aggregations.get("AppId");
Map<Long, Long> newMap = new TreeMap(Collections.reverseOrder());
for (Terms.Bucket entry : byApp.getBuckets()) {
newMap.put(entry.getDocCount(), Long.parseLong(entry.getKey().toString()));
}
return newMap.values().stream().limit(key).collect(Collectors.toList());
.maximumSize(1000)
.refreshAfterWrite(60, TimeUnit.SECONDS)
.build(
new CacheLoader<Integer, List<Long>>() {
public List<Long> load(Integer key) {
return getTopAdvertFromEs(key);
}
public ListenableFutureTask<List<Long>> reload(final Integer key, List<Long> prevGraph) {
ListenableFutureTask<List<Long>> task = ListenableFutureTask.create(() -> getTopAdvertFromEs(key));
Executors.newSingleThreadExecutor().execute(task);
return task;
}
});
private List<Long> getTopAdvertFromEs(Integer key) {
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(matchAllQuery())
.withSearchType(SearchType.DEFAULT)
.withIndices(couponLogEsConfig.getIndexPrefix() + "-" + getYesterdayDate()).withTypes(couponLogEsConfig.getTypeName())
.addAggregation(terms("AppId").field("appId").size(0))
.build();
Aggregations aggregations = esTemplate.query(searchQuery, response -> response.getAggregations());
Terms byApp = aggregations.get("AppId");
Map<Long, Long> newMap = new TreeMap(Collections.reverseOrder());
for (Terms.Bucket entry : byApp.getBuckets()) {
newMap.put(entry.getDocCount(), Long.parseLong(entry.getKey().toString()));
}
return newMap.values().stream().limit(key).collect(Collectors.toList());
}
private List<Long> buildTopAdvIds(ReqAdvertFlowEstimate reqAdvertFlowEstimate) {
List<Long> topAdvertList = topAdvertListCache.getUnchecked(TOPADV_COUNT);
logger.info("TOPADVETIDS:"+JSON.toJSONString(topAdvertList)+"BINDAPP:"+JSON.toJSONString(reqAdvertFlowEstimate.getBindApp()));
if (reqAdvertFlowEstimate.getBindApp() != null&&reqAdvertFlowEstimate.getBindApp().size()>0) {//过滤定向APP的广告列表
topAdvertList = topAdvertList.stream().filter(x -> reqAdvertFlowEstimate.getBindApp().contains(Integer.parseInt(x.toString()))).collect(Collectors.toList());
}
return topAdvertList;
}
阅读全文
0 0
- Guava---缓存
- guava缓存
- guava缓存
- Guava缓存
- [Google Guava]-缓存详解
- [Google Guava]-缓存清除
- Google Guava-缓存
- Guava 缓存 使用
- Guava Cache缓存
- Google Guava-缓存
- [Google Guava] 3-缓存
- [Google Guava] 缓存
- goggle 缓存guava
- 三、Guava的缓存
- [Google Guava] 3-缓存
- guava实现本地缓存
- guava缓存底层实现
- google Guava缓存
- 在centos7下搭建FTP,使本地电脑与虚拟机能上传下载文件
- 11.30学习计划
- 数字图像的空间域滤波和频率域滤波
- Bixby在中国市场上线,三星推动智能手机全面跨入AI时代
- 一个双线性配对(双线性映射)的例子
- guava缓存
- 原生XHR对象
- 微信小程序之起步(更新中)
- JFreeChart柱状图的颜色设置与宽度分配
- NLP开源框架
- BZOJ2115: [Wc2011] Xor(异或方程组)
- Kafka集群搭建
- CG插画入门教程之人体动态基础与面部画法分析
- QT 使用Pixmap绘制图像