As a disclaimer, I'm new to Caffeine and exploring out this lightweight approach.
I have a collection that is fetched from a database that consists of more than 20K of simple ItemLOV two-attribute objects. They are pulled, converted / cast as:
List<OutletsSelectBox> result = new ArrayList<>();
for(int i = 0; i<objlist.size(); i++){
Object row = objlist.get(i);
Object[] item = (Object[]) row;
SkusSelectBox ssb = new SkusSelectBox();
ssb.setItemId(String.valueOf(item[0].toString()));
ssb.setItemName(String.valueOf(item[1].toString()));
result.add(ssb);
}
What I'm looking for is to set the cached items into the setItems method of a third-party component that I have. The setItems, a public void method, allows three options to be parsed either in:
public void setItems(final Collection<T> items)
public void setItems(Stream<T> streamOfItems)
public void setItems(@SuppressWarnings("unchecked") final T... items)
I noticed that there is a similar posting: Simple Way to Cache a List of Collection in Java but what I am not sure about is:
- Should my list should use a memoize or the cache builder?
- If memoize is best used, is the Supplier cast used in the sample code (in the linked posting) is from the java.util package or the Guava package?
- Does the cache needs to be recast into a list again prior to be set into the setItems method?
- For the memoizeWithExpiration method, can the existing code above be transposed / moved as the delegate parameter instead of a empty Supplier Collection or do we need to do it within the get() method? It's great to have an existing list parsed in as the delegate, but not very sure of it though.