forked from eclipse-vertx/vertx-http-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheImpl.java
More file actions
47 lines (37 loc) · 1.05 KB
/
CacheImpl.java
File metadata and controls
47 lines (37 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package io.vertx.httpproxy.impl;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.httpproxy.cache.CacheOptions;
import io.vertx.httpproxy.spi.cache.Cache;
import io.vertx.httpproxy.spi.cache.Resource;
import java.util.*;
/**
* Simplistic implementation.
*/
public class CacheImpl implements Cache {
private final int maxSize;
private final Map<String, Resource> data;
public CacheImpl(CacheOptions options) {
this.maxSize = options.getMaxSize();
this.data = Collections.synchronizedMap(new LinkedHashMap<>() {
@Override
protected boolean removeEldestEntry(Map.Entry<String, Resource> eldest) {
return size() > maxSize;
}
});
}
@Override
public Future<Void> put(String key, Resource value) {
data.put(key, value);
return Future.succeededFuture();
}
@Override
public Future<Resource> get(String key) {
return Future.succeededFuture(data.get(key));
}
@Override
public Future<Void> remove(String key) {
data.remove(key);
return Future.succeededFuture();
}
}