We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b9600f6 commit 07e47bfCopy full SHA for 07e47bf
1 file changed
src/main/java/org/example/StaticFileHandler.java
@@ -12,14 +12,21 @@
12
public class StaticFileHandler {
13
private static final String WEB_ROOT = "www";
14
private byte[] fileBytes;
15
+ private final FileCache cache = new FileCache();
16
17
public StaticFileHandler(){}
18
19
private void handleGetRequest(String uri) throws IOException {
-
20
+ if (cache.contains(uri)) {
21
+ System.out.println("✓ Cache hit for: " + uri);
22
+ fileBytes = cache.get(uri);
23
+ return;
24
+ }
25
+ System.out.println("✗ Cache miss for: " + uri);
26
File file = new File(WEB_ROOT, uri);
27
fileBytes = Files.readAllBytes(file.toPath());
28
29
+ cache.put(uri, fileBytes);
30
}
31
32
public void sendGetRequest(OutputStream outputStream, String uri) throws IOException{
0 commit comments