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.
2 parents d687573 + 12997b9 commit af528a2Copy full SHA for af528a2
unidev-common/src/main/java/com/unidev/platform/cache/WeakConcurrentCache.java
@@ -0,0 +1,25 @@
1
+package com.unidev.platform.cache;
2
+
3
+import lombok.Getter;
4
5
+import java.lang.ref.WeakReference;
6
+import java.util.concurrent.ConcurrentHashMap;
7
8
+/**
9
+ * Weak concurrent cache
10
+ * @param <K>
11
+ * @param <V>
12
+ */
13
+@Getter
14
+public class WeakConcurrentCache<K, V> {
15
+ private final ConcurrentHashMap<K, WeakReference<V>> cache = new ConcurrentHashMap<>();
16
17
+ public void put(K key, V value) {
18
+ cache.put(key, new WeakReference<>(value));
19
+ }
20
21
+ public V get(K key) {
22
+ WeakReference<V> weakRef = cache.get(key);
23
+ return weakRef == null ? null : weakRef.get();
24
25
+}
0 commit comments