io.vertx.up.uca.cache.RapidT Maven / Gradle / Ivy
package io.vertx.up.uca.cache;
import io.vertx.core.Future;
import io.vertx.up.atom.Kv;
import io.vertx.up.unity.Ux;
import java.util.Objects;
import java.util.function.Supplier;
/**
* Direct Map to Shared
*
* @author Lang
*/
class RapidT extends AbstractRapid {
RapidT(final String cacheKey, final int expired) {
super(cacheKey, expired);
}
@Override
public Future cached(final String key, final Supplier> executor) {
Objects.requireNonNull(key);
return this.pool.get(key).compose(queried -> {
if (Objects.isNull(queried)) {
return executor.get()
.compose(actual -> 0 < this.expired ?
this.pool.put(key, actual, this.expired) :
this.pool.put(key, actual)
)
.compose(Kv::value);
} else {
this.logger().info("[ Cache ] \u001b[0;37mK = `{1}`, P = `{0}`\u001b[m", this.pool.name(), key);
return Ux.future(queried);
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy