This commit is contained in:
@@ -180,10 +180,11 @@
|
|||||||
-->
|
-->
|
||||||
<resource-servlet webroot="root" index="index.html">
|
<resource-servlet webroot="root" index="index.html">
|
||||||
<!--
|
<!--
|
||||||
|
【节点在<resource-servlet>中唯一】
|
||||||
资源缓存的配置, 默认存在一个含默认属性的caches节点
|
资源缓存的配置, 默认存在一个含默认属性的caches节点
|
||||||
limit: 资源缓存最大容量, 默认: 0, 为0表示不缓存, 单位可以是B、K、M、G,不区分大小写
|
limit: 资源缓存最大容量, 默认: 0, 为0表示不缓存, 单位可以是B、K、M、G,不区分大小写
|
||||||
lengthmax: 可缓存的文件大小上限, 默认: 1M(超过1M的文件不会被缓存)
|
lengthmax: 可缓存的文件大小上限, 默认: 1M(超过1M的文件不会被缓存)
|
||||||
watch: 是否监控缓存文件的变化, 默认不监控
|
watch: 是否监控缓存文件的变化, 默认为false,不监控
|
||||||
-->
|
-->
|
||||||
<cache limit="0M" lengthmax="1M" watch="false"/>
|
<cache limit="0M" lengthmax="1M" watch="false"/>
|
||||||
<!--
|
<!--
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import java.util.AbstractMap.SimpleEntry;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.LongAdder;
|
import java.util.concurrent.atomic.LongAdder;
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
import java.util.regex.*;
|
import java.util.regex.*;
|
||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
@@ -108,8 +107,6 @@ public class HttpResourceServlet extends HttpServlet {
|
|||||||
|
|
||||||
protected WatchThread watchThread;
|
protected WatchThread watchThread;
|
||||||
|
|
||||||
protected Predicate<String> ranges;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(HttpContext context, AnyValue config) {
|
public void init(HttpContext context, AnyValue config) {
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
@@ -118,15 +115,12 @@ public class HttpResourceServlet extends HttpServlet {
|
|||||||
if (rootstr.indexOf(':') < 0 && rootstr.indexOf('/') != 0 && System.getProperty("APP_HOME") != null) {
|
if (rootstr.indexOf(':') < 0 && rootstr.indexOf('/') != 0 && System.getProperty("APP_HOME") != null) {
|
||||||
rootstr = new File(System.getProperty("APP_HOME"), rootstr).getPath();
|
rootstr = new File(System.getProperty("APP_HOME"), rootstr).getPath();
|
||||||
}
|
}
|
||||||
String rangesValue = config.getValue("ranges");
|
|
||||||
this.ranges = rangesValue != null ? Pattern.compile(rangesValue).asPredicate() : null;
|
|
||||||
try {
|
try {
|
||||||
this.root = new File(rootstr).getCanonicalFile();
|
this.root = new File(rootstr).getCanonicalFile();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
this.root = new File(rootstr);
|
this.root = new File(rootstr);
|
||||||
}
|
}
|
||||||
AnyValue cacheconf = config.getAnyValue("cache");
|
AnyValue cacheconf = config.getAnyValue("cache");
|
||||||
if (cacheconf == null) cacheconf = config.getAnyValue("caches"); //兼容旧参数
|
|
||||||
if (cacheconf != null) {
|
if (cacheconf != null) {
|
||||||
this.cachelimit = parseLenth(cacheconf.getValue("limit"), 0 * 1024 * 1024L);
|
this.cachelimit = parseLenth(cacheconf.getValue("limit"), 0 * 1024 * 1024L);
|
||||||
this.cachelengthmax = parseLenth(cacheconf.getValue("lengthmax"), 1 * 1024 * 1024L);
|
this.cachelengthmax = parseLenth(cacheconf.getValue("lengthmax"), 1 * 1024 * 1024L);
|
||||||
@@ -274,7 +268,7 @@ public class HttpResourceServlet extends HttpServlet {
|
|||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
if (this.file == null) return;
|
if (this.file == null) return;
|
||||||
if (this.content != null) {
|
if (this.content != null) {
|
||||||
this.servlet.cachedLength.add(0L - this.content.remaining());
|
this.servlet.cachedLength.add(0L - this.content.remaining());
|
||||||
this.content = null;
|
this.content = null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user