Skip to content

Instantly share code, notes, and snippets.

import java.util.Calendar;
import lombok.Builder;
import lombok.Value;
@Builder
@Value
public class JacksonExample {
private String fieldOne;
private String fieldTwo;
// Snippet of code used to evict invoices cache when mqtt messages arrive. We assume we have an mqttComponent and
// an invoiceService correctly defined in the current scope
mqttComponent.subscribeToTopicWithEmptyPayload("caches/invoices/+/evict",evictInvoiceCache(),1);
// ...
private Function<String,Void> evictInvoiceCache() {
return topic->{
@Component
public class MqttComponentPurePahoImpl implements MqttComponent {
private final String mqttUrl;
private final String mqttUser;
private final String mqttPassword;
private final String displayNameNode;
private final ObjectWriter objectWriter;
private MqttClient mqttClient;
<cache name="invoicesCache" eternal="false" maxElementsInMemory="1000" overflowToDisk="false"
diskPersistent="false" timeToIdleSeconds="0" timeToLiveSeconds="3600" memoryStoreEvictionPolicy="LRU"/>
@Override
@Cacheable(value = "invoicesCache", key = "#invoiceId")
public Invoice getInvoice(String invoiceId) {
// Get data from backend service
}
@Override
@CacheEvict(value = "invoicesCache", key = "#invoiceId")
public void evictInvoicesCache(String invoiceId) {