Skip to content

Commit

Permalink
Renamed AutoCacheFactoryBuilder.autoCache() to AutoCacheFactoryBuilde…
Browse files Browse the repository at this point in the history
…r.autoCacheBuilder()
  • Loading branch information
pellse committed Apr 11, 2023
1 parent 3250091 commit d8ea352
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,23 @@
import java.util.function.Function;
import java.util.function.Predicate;

import static io.github.pellse.reactive.assembler.caching.AutoCacheFactory.autoCache;
import static io.github.pellse.reactive.assembler.caching.CacheEvent.toCacheEvent;

public interface AutoCacheFactoryBuilder {

static <R> WindowingStrategyBuilder<R, CacheEvent<R>> autoCache(Flux<R> dataSource) {
return autoCache(dataSource, CacheEvent::updated);
static <R> WindowingStrategyBuilder<R, CacheEvent<R>> autoCacheBuilder(Flux<R> dataSource) {
return autoCacheBuilder(dataSource, CacheEvent::updated);
}

static <U, R> WindowingStrategyBuilder<R, ? extends CacheEvent<R>> autoCache(
static <U, R> WindowingStrategyBuilder<R, ? extends CacheEvent<R>> autoCacheBuilder(
Flux<U> dataSource,
Predicate<U> isUpdateEvent,
Function<U, R> cacheEventValueExtractor) {
return autoCacheEvents(dataSource.map(toCacheEvent(isUpdateEvent, cacheEventValueExtractor)));
}

static <U, R, T extends CacheEvent<R>> WindowingStrategyBuilder<R, T> autoCache(Flux<U> dataSource, Function<U, T> mapper) {
static <U, R, T extends CacheEvent<R>> WindowingStrategyBuilder<R, T> autoCacheBuilder(Flux<U> dataSource, Function<U, T> mapper) {
return autoCacheEvents(dataSource.map(mapper));
}

Expand Down Expand Up @@ -129,7 +130,7 @@ public AutoCacheFactoryDelegateBuilder<R> scheduler(Scheduler scheduler) {

@Override
public <ID, RRC> CacheTransformer<ID, R, RRC> build() {
return AutoCacheFactory.autoCache(dataSource, windowingStrategy, errorHandler, eventSource, scheduler);
return autoCache(dataSource, windowingStrategy, errorHandler, eventSource, scheduler);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import static io.github.pellse.reactive.assembler.Rule.rule;
import static io.github.pellse.reactive.assembler.RuleMapper.*;
import static io.github.pellse.reactive.assembler.caching.AutoCacheFactory.OnErrorContinue.onErrorContinue;
import static io.github.pellse.reactive.assembler.caching.AutoCacheFactoryBuilder.autoCache;
import static io.github.pellse.reactive.assembler.caching.AutoCacheFactoryBuilder.autoCacheBuilder;
import static io.github.pellse.reactive.assembler.caching.AutoCacheFactoryBuilder.autoCacheEvents;
import static io.github.pellse.reactive.assembler.caching.CacheEvent.*;
import static io.github.pellse.reactive.assembler.caching.CacheFactory.cache;
Expand Down Expand Up @@ -458,8 +458,8 @@ public void testReusableAssemblerBuilderWithAutoCaching() {
var assembler = assemblerOf(Transaction.class)
.withCorrelationIdExtractor(Customer::customerId)
.withAssemblerRules(
rule(BillingInfo::customerId, oneToOne(cached(this::getBillingInfo, autoCache(billingInfoFlux).maxWindowSize(10).build(), cff1, cff2))),
rule(OrderItem::customerId, oneToMany(OrderItem::id, cached(this::getAllOrders, cache(), autoCache(orderItemFlux).maxWindowSize(10).build()))),
rule(BillingInfo::customerId, oneToOne(cached(this::getBillingInfo, autoCacheBuilder(billingInfoFlux).maxWindowSize(10).build(), cff1, cff2))),
rule(OrderItem::customerId, oneToMany(OrderItem::id, cached(this::getAllOrders, cache(), autoCacheBuilder(orderItemFlux).maxWindowSize(10).build()))),
Transaction::new)
.build();

Expand Down Expand Up @@ -488,7 +488,7 @@ public void testReusableAssemblerBuilderWithAutoCaching2() {
var assembler = assemblerOf(Transaction.class)
.withCorrelationIdExtractor(Customer::customerId)
.withAssemblerRules(
rule(BillingInfo::customerId, oneToOne(cached(autoCache(billingInfoFlux).maxWindowSize(4).build()))),
rule(BillingInfo::customerId, oneToOne(cached(autoCacheBuilder(billingInfoFlux).maxWindowSize(4).build()))),
rule(OrderItem::customerId, oneToMany(OrderItem::id, this::getAllOrders)),
Transaction::new)
.build();
Expand Down Expand Up @@ -519,8 +519,8 @@ public void testReusableAssemblerBuilderWithAutoCaching3() {
var assembler = assemblerOf(Transaction.class)
.withCorrelationIdExtractor(Customer::customerId)
.withAssemblerRules(
rule(BillingInfo::customerId, oneToOne(cached(this::getBillingInfo, autoCache(dataSource1).build()))),
rule(OrderItem::customerId, oneToMany(OrderItem::id, cached(this::getAllOrders, autoCache(dataSource2).maxWindowSize(1).build()))),
rule(BillingInfo::customerId, oneToOne(cached(this::getBillingInfo, autoCacheBuilder(dataSource1).build()))),
rule(OrderItem::customerId, oneToMany(OrderItem::id, cached(this::getAllOrders, autoCacheBuilder(dataSource2).maxWindowSize(1).build()))),
Transaction::new)
.build();

Expand Down Expand Up @@ -555,12 +555,12 @@ public void testReusableAssemblerBuilderWithAutoCachingLifeCycleEventListener()
.withCorrelationIdExtractor(Customer::customerId)
.withAssemblerRules(
rule(BillingInfo::customerId, oneToOne(cached(this::getBillingInfo,
autoCache(billingInfoFlux)
autoCacheBuilder(billingInfoFlux)
.maxWindowSize(3)
.lifeCycleEventSource(lifeCycleEventBroadcaster)
.build()))),
rule(OrderItem::customerId, oneToMany(OrderItem::id, cached(this::getAllOrders, cache(),
autoCache(orderItemFlux)
autoCacheBuilder(orderItemFlux)
.maxWindowSize(3)
.lifeCycleEventSource(lifeCycleEventBroadcaster)
.build()))),
Expand Down Expand Up @@ -593,7 +593,7 @@ public void testReusableAssemblerBuilderWithAutoCachingError() {
.withCorrelationIdExtractor(Customer::customerId)
.withAssemblerRules(
rule(BillingInfo::customerId, oneToOne(cached(
autoCache(billingInfoFlux)
autoCacheBuilder(billingInfoFlux)
.errorHandler(onErrorContinue(error -> assertInstanceOf(NullPointerException.class, error)))
.build()))),
rule(OrderItem::customerId, oneToMany(OrderItem::id, this::getAllOrders)),
Expand Down Expand Up @@ -641,7 +641,7 @@ public void testReusableAssemblerBuilderWithAutoCachingEvents() {
.build();

CacheTransformer<Long, OrderItem, List<OrderItem>> orderItemAutoCache =
autoCache(orderItemFlux, toCacheEvent(CDCAdd.class::isInstance, CDC::item))
autoCacheBuilder(orderItemFlux, toCacheEvent(CDCAdd.class::isInstance, CDC::item))
.maxWindowSize(3)
.build();

Expand Down Expand Up @@ -699,7 +699,7 @@ public void testReusableAssemblerBuilderWithAutoCachingEvents2() {
.maxWindowSize(3)
.build()))),
rule(OrderItem::customerId, oneToMany(OrderItem::id, cached(getAllOrders, cache(),
autoCache(orderItemFlux, CDCAdd.class::isInstance, CDC::item)
autoCacheBuilder(orderItemFlux, CDCAdd.class::isInstance, CDC::item)
.maxWindowSize(3)
.build()))),
Transaction::new)
Expand Down Expand Up @@ -791,13 +791,13 @@ public void testLongRunningAutoCachingEvents() throws InterruptedException {
.withCorrelationIdExtractor(Customer::customerId)
.withAssemblerRules(
rule(BillingInfo::customerId, oneToOne(cached(getBillingInfo,
autoCache(billingInfoFlux, CDCAdd.class::isInstance, CDC::item)
autoCacheBuilder(billingInfoFlux, CDCAdd.class::isInstance, CDC::item)
.maxWindowSize(3)
.lifeCycleEventSource(lifeCycleEventBroadcaster)
.scheduler(newParallel("billing-info"))
.build()))),
rule(OrderItem::customerId, oneToMany(OrderItem::id, cached(getAllOrders,
autoCache(orderItemFlux, CDCAdd.class::isInstance, CDC::item)
autoCacheBuilder(orderItemFlux, CDCAdd.class::isInstance, CDC::item)
.maxWindowSize(3)
.lifeCycleEventSource(lifeCycleEventBroadcaster)
.scheduler(newParallel("order-item"))
Expand Down

0 comments on commit d8ea352

Please sign in to comment.