HtmlCache.java
1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.bckefu.excel.cache;
import com.bckefu.excel.entity.ExcelToHtmlParams;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import java.util.concurrent.TimeUnit;
/**
* @author : caoliang
* @date : 2017/11/20 下午2:48
*/
public class HtmlCache {
private static LoadingCache<ExcelToHtmlParams, String> loadingCache;
static {
loadingCache = CacheBuilder.newBuilder().expireAfterWrite(7, TimeUnit.DAYS).maximumSize(200)
.build(new CacheLoader<ExcelToHtmlParams, String>() {
@Override
public String load(ExcelToHtmlParams params) throws Exception {
return new ExcelToHtmlServer(params).printPage();
}
});
}
public static String getHtml(ExcelToHtmlParams params) {
try {
return loadingCache.get(params);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void setLoadingCache(LoadingCache<ExcelToHtmlParams, String> loadingCache) {
HtmlCache.loadingCache = loadingCache;
}
}