Skip to main content

Compiler Cache

The compiler cache stores the bytecode produced by the runtime compiler, so later runs skip compilation and start faster.

Use the experimental directory cache below, or implement the run.endive.compiler.Cache interface:

public interface Cache {
byte[] get(String key) throws IOException;
void putIfAbsent(String key, byte[] data) throws IOException;
}

The compiler uses the module digest (default SHA-256) as the cache key. For example, "sha-256:KRgyTkCm43c34ksqtA8gmdDw4YCfquC2G0qfIFCpb+w=" could be a key. The cached value is a JAR containing the module's compiled bytecode.

The directory cache​

Security Consideration

The cache stores bytecode on disk without integrity checks. Keep the directory private (chmod 700) and never share it across trust boundaries.

DirectoryCache stores one jar per module under a directory of your choice. Writes are atomic, so several processes can share a cache. Nothing is ever evicted: delete files to free disk space.

Add the dependency:

<dependency>
<groupId>run.endive</groupId>
<artifactId>dircache-experimental</artifactId>
</dependency>

Create the cache:

import java.nio.file.Path;
import run.endive.experimental.dircache.DirectoryCache;

var cache = new DirectoryCache(Path.of("cache"));

Configure the compiler to use the cache via MachineFactoryCompiler.builder(...):

var module = Parser.parse(new File("your.wasm"));
var instance = Instance.builder(module).
withMachineFactory(
MachineFactoryCompiler.builder(module).withCache(cache).compile()
).
build();