There was an error while loading. Please reload this page.
1 parent 3b34b91 commit b2ef693Copy full SHA for b2ef693
1 file changed
src/main/java/org/example/CacheFilter.java
@@ -0,0 +1,23 @@
1
+package org.example;
2
+
3
+import java.io.IOException;
4
5
+public class CacheFilter {
6
+ private final FileCache cache = new FileCache();
7
8
+ public byte[] getOrFetch(String uri, FileProvider provider) throws IOException {
9
+ if (cache.contains(uri)) {
10
+ System.out.println("✓ Cache hit for: " + uri);
11
+ return cache.get(uri);
12
+ }
13
+ System.out.println("✗ Cache miss for: " + uri);
14
+ byte[] fileBytes = provider.fetch(uri);
15
+ cache.put(uri, fileBytes);
16
+ return fileBytes;
17
18
19
+ @FunctionalInterface
20
+ public interface FileProvider {
21
+ byte[] fetch(String uri) throws IOException;
22
23
+}
0 commit comments