Add loading cache for GH CVE project data
To better support fast lookups of CVE data and reduce loading time, we should add a loading precache for Github CVE Project data. This will require a few changes to the CVE Source service to properly cache these entries.
Some implementation notes:
@Startup
should be added to the implementation as a class-level annotation. This tells Quarkus to start this service and start the cache as part of the runtime boot operation of the application. To make sure we don't block, we shouldn't wait for results from the initial load of the cache, but instead, just trigger and keep going. The cache should have a thread pool, so we don't need to worry about bogging the system down as it will be able to be tuned and manage itself.
Quarkus should come with Caffeine cache built in as Quarkus makes use of it. While some projects do use Guava, I'll be looking to start migrating away from it where possible to the Quarkus-supported Caffeine cache. There should be examples in the Git ECA service, and soon in the membership service of loading caches that use executor pools, even if they are written using Guava.
A quick example of this is the following code:
@Startup
@ApplicationScoped
public class TheClass {
@Inject
ManagedExecutor exec;
// separate internal loading cache for HA member org lookups
private LoadingCache<String, List<SomeObjectType>> loadingCache;
@PostConstruct
void init() {
this.loadingCache = Caffeine.newBuilder().executor(exec).build(this::loadData);
// list of string keys, and tell it to use loading cache to get.
listOfKeys.forEach(loadingCache::get);
}
// retrieves loaded data
private List<SomeObjectType> getData(String key) {
return loadingCache.get(key);
}
// source for loaded data, shouldn't be called externally (as it would be uncached/expensive)
private List<SomeObjectType> loadData(String key) {
return theData;
}
}