BAEL-1109 Introduction to JCache (#2594)
* Evaluation article: Different Types of Bean Injection in Spring * added tests & changed configuration to Java-based config * removed xml config files * rename unit tests * BAEL-972 - Apache Commons Text * remove code from evaluation article * remove code from evaluation article * BAEL-972 - Apache Commons Text - added another example * BAEL-972 - Apache Commons Text - just indentation * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java - fix problems * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * fix formatting * BAEL-1033 minor refactor * BAEL-1035 Introduction to Eclipse Collections * format * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * cleanup * cleanup * BAEL-1109 Introduction to JCache * BAEL-1109 Introduction to JCache * remove unneeded property in pom.xml * fix formatting
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.jcache;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.cache.event.CacheEntryCreatedListener;
|
||||
import javax.cache.event.CacheEntryEvent;
|
||||
import javax.cache.event.CacheEntryListenerException;
|
||||
import javax.cache.event.CacheEntryUpdatedListener;
|
||||
|
||||
public class SimpleCacheEntryListener implements CacheEntryCreatedListener<String, String>, CacheEntryUpdatedListener<String, String>, Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -712657810462878763L;
|
||||
private boolean updated;
|
||||
private boolean created;
|
||||
|
||||
public boolean getUpdated() {
|
||||
return this.updated;
|
||||
}
|
||||
|
||||
public boolean getCreated() {
|
||||
return this.created;
|
||||
}
|
||||
|
||||
public void onUpdated(Iterable<CacheEntryEvent<? extends String, ? extends String>> events) throws CacheEntryListenerException {
|
||||
this.updated = true;
|
||||
}
|
||||
|
||||
public void onCreated(Iterable<CacheEntryEvent<? extends String, ? extends String>> events) throws CacheEntryListenerException {
|
||||
this.created = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.jcache;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.cache.integration.CacheLoader;
|
||||
import javax.cache.integration.CacheLoaderException;
|
||||
|
||||
public class SimpleCacheLoader implements CacheLoader<Integer, String> {
|
||||
|
||||
@Override
|
||||
public String load(Integer key) throws CacheLoaderException {
|
||||
return "fromCache" + key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, String> loadAll(Iterable<? extends Integer> keys) throws CacheLoaderException {
|
||||
Map<Integer, String> data = new HashMap<>();
|
||||
for (int key : keys) {
|
||||
data.put(key, load(key));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.jcache;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.cache.processor.EntryProcessor;
|
||||
import javax.cache.processor.EntryProcessorException;
|
||||
import javax.cache.processor.MutableEntry;
|
||||
|
||||
public class SimpleEntryProcessor implements EntryProcessor<String, String, String>, Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5616476363722945132L;
|
||||
|
||||
public String process(MutableEntry<String, String> entry, Object... args) throws EntryProcessorException {
|
||||
|
||||
if (entry.exists()) {
|
||||
String current = entry.getValue();
|
||||
entry.setValue(current + " - modified");
|
||||
return current;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user