We have some legacy code abusing static class variables and functions for caching. Example:
public class MetaDataCache {
static LoadingCache<String, GcsMetadata> metadataCache;
// initial set up on server start up
public static void setup(Config config){
metadataCache =
CacheBuilder.newBuilder()
.refreshAfterWrite(30, TimeUnit.SECONDS)
.build(getCacheLoader());
}
// load and reload the cache
private static CacheLoader<String, GcsMetadata> getCacheLoader() {}
// access cache and get value
public static GcsMetadata getMetaData(String key) {
return metadataCache.get(key);
}
}
public class Application {
public static void main(){
MetaDataCache.setup(config);
MetaDataCache.getMetaData("cacheKey");
}
}
Now I'm trying refactoring the MetaDataCache class to avoid using static functions for dependency injection with Dagger 2, what's the best approach?