![JAR search and dependency download from the Maven repository](/logo.png)
win.doyto.query.cache.CacheWrapper Maven / Gradle / Ivy
package win.doyto.query.cache;
import org.springframework.cache.Cache;
/**
* CacheWrapper
*
* @author f0rb
*/
public interface CacheWrapper {
@SuppressWarnings("unchecked")
static V invoke(Cache cache, Object key, Invocable invocable) {
if (cache == null || key == null) {
return invocable.invoke();
}
Cache.ValueWrapper valueWrapper = cache.get(key);
if (valueWrapper != null) {
return (V) valueWrapper.get();
}
V value = invocable.invoke();
cache.put(key, value);
return value;
}
static DefaultCacheWrapper createInstance() {
return new DefaultCacheWrapper<>();
}
default T execute(String key, Invocable invocable) {
return CacheWrapper.invoke(getCache(), key, invocable);
}
void setCache(Cache cache);
Cache getCache();
default void evict(String key) {
getCache().evict(key);
}
default void clear() {
getCache().clear();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy