MCPcopy
hub / github.com/apache/druid / MapCache

Class MapCache

server/src/main/java/org/apache/druid/client/cache/MapCache.java:38–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36/**
37 */
38public class MapCache implements Cache
39{
40 public static Cache create(long sizeInBytes)
41 {
42 return new MapCache(new ByteCountingLRUMap(sizeInBytes));
43 }
44
45 private final Map<ByteBuffer, byte[]> baseMap;
46 private final ByteCountingLRUMap byteCountingLRUMap;
47
48 private final Map<String, byte[]> namespaceId;
49 private final AtomicInteger ids;
50
51 private final Object clearLock = new Object();
52
53 private final AtomicLong hitCount = new AtomicLong(0);
54 private final AtomicLong missCount = new AtomicLong(0);
55
56 MapCache(
57 ByteCountingLRUMap byteCountingLRUMap
58 )
59 {
60 this.byteCountingLRUMap = byteCountingLRUMap;
61 this.baseMap = Collections.synchronizedMap(byteCountingLRUMap);
62
63 namespaceId = new HashMap<>();
64 ids = new AtomicInteger();
65 }
66
67 @Override
68 public CacheStats getStats()
69 {
70 return new CacheStats(
71 hitCount.get(),
72 missCount.get(),
73 byteCountingLRUMap.size(),
74 byteCountingLRUMap.getNumBytes(),
75 byteCountingLRUMap.getEvictionCount(),
76 0,
77 0
78 );
79 }
80
81 @Override
82 public byte[] get(NamedKey key)
83 {
84 final byte[] retVal;
85 synchronized (clearLock) {
86 retVal = baseMap.get(computeKey(getNamespaceId(key.namespace), key.key));
87 }
88 if (retVal == null) {
89 missCount.incrementAndGet();
90 } else {
91 hitCount.incrementAndGet();
92 }
93 return retVal;
94 }
95

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected