Skip to content

Commit 07e47bf

Browse files
committed
har lagt till i line 20-25 samt line 29
1 parent b9600f6 commit 07e47bf

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/main/java/org/example/StaticFileHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@
1212
public class StaticFileHandler {
1313
private static final String WEB_ROOT = "www";
1414
private byte[] fileBytes;
15+
private final FileCache cache = new FileCache();
1516

1617
public StaticFileHandler(){}
1718

1819
private void handleGetRequest(String uri) throws IOException {
19-
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);
2026
File file = new File(WEB_ROOT, uri);
2127
fileBytes = Files.readAllBytes(file.toPath());
2228

29+
cache.put(uri, fileBytes);
2330
}
2431

2532
public void sendGetRequest(OutputStream outputStream, String uri) throws IOException{

0 commit comments

Comments
 (0)