Skip to content

Commit 9008d66

Browse files
committed
clearCompileCache method
1 parent a42ff8e commit 9008d66

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

README-EN-source.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ You can cache scripts before first execution using the following method to ensur
341341
include::./src/test/java/com/alibaba/qlexpress4/Express4RunnerTest.java[tag=parseToCache]
342342
----
343343

344+
Note that this cache has an unlimited size; be sure to control its size in your application. You can periodically clear the compilation cache by calling the `clearCompileCache` method.
345+
344346
=== Setting Timeout
345347

346348
You can set a timeout for scripts to prevent infinite loops or other reasons from causing excessive consumption of application resources.

README-source.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ include::./src/test/java/com/alibaba/qlexpress4/Express4RunnerTest.java[tag=cach
343343
include::./src/test/java/com/alibaba/qlexpress4/Express4RunnerTest.java[tag=parseToCache]
344344
----
345345

346+
注意该缓存的大小是无限的,业务上注意控制大小,可以调用 `clearCompileCache` 方法定期清空编译缓存。
347+
346348
=== 设置超时时间
347349

348350
可以给脚本设置一个超时时间,防止其中存在死循环或者其他原因导致应用资源被过量消耗。

src/main/java/com/alibaba/qlexpress4/Express4Runner.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,16 @@ public Value loadField(Object object, String fieldName) {
428428
return reflectLoader.loadField(object, fieldName, true, PureErrReporter.INSTANCE);
429429
}
430430

431+
/**
432+
* Clear the compilation cache.
433+
* This method clears the cache that stores compiled scripts for performance optimization.
434+
* When the cache is cleared, subsequent script executions will need to recompile the scripts,
435+
* which may temporarily impact performance until the cache is rebuilt.
436+
*/
437+
public void clearCompileCache() {
438+
compileCache.clear();
439+
}
440+
431441
private Future<QCompileCache> getParseFuture(String script) {
432442
Future<QCompileCache> parseFuture = compileCache.get(script);
433443
if (parseFuture != null) {

0 commit comments

Comments
 (0)