This Apache Druid module provides a per-lookup caching mechanism for JDBC data sources. The main goal of this cache is to speed up the access to a high latency lookup sources and to provide a caching isolation for every lookup source. Thus user can define various caching strategies or and implementation per lookup, even if the source is the same. This module can be used side to side with other lookup module like the global cached lookup module.

To use this Apache Druid extension, in the extensions load list.

If using JDBC, you will need to add your database’s client JAR files to the extension’s directory. For Postgres, the connector JAR is already included. See the MySQL extension documentation for instructions to obtain MySQL or connector libraries. Copy or symlink the downloaded file to extensions/druid-lookups-cached-single under the distribution root directory.

First part is the data fetcher layer API DataFetcher, that exposes a set of fetch methods to fetch data from the actual Lookup dimension source. For instance JdbcDataFetcher provides an implementation of DataFetcher that can be used to fetch key/value from a RDBMS via JDBC driver. If you need new type of data fetcher, all you need to do, is to implement the interface DataFetcher and load it via another druid module.

This extension comes with two different caching strategies. First strategy is a poll based and the second is a load based.

Poll lookup cache

The poll strategy cache strategy will fetch and swap all the pair of key/values periodically from the lookup source. Hence, user should make sure that the cache can fit all the data. The current implementation provides 2 type of poll cache, the first is on-heap (uses immutable map), while the second uses MapDB based off-heap map. User can also implement a different lookup polling cache by implementing PollingCacheFactory and interfaces.

Loading lookup

Note that the current implementation of offHeapPolling and onHeapPolling will create two caches one to lookup value based on key and the other to reverse lookup the key from value

Example of Polling On-heap Lookup

This example demonstrates a polling cache that will update its on-heap cache every 10 minutes

Example Polling Off-heap Lookup

This example demonstrates an off-heap lookup that will be cached once and never swapped (pollPeriod == null)

Example Loading On-heap Guava
Example Loading Off-heap MapDB

Off heap cache is backed by MapDB implementation. MapDB is using direct memory as memory pool, please take that into account when limiting the JVM direct memory setup.