Hello, I have a basic question about the configuration of a cache for an aggregate repository.
When should a define the beans for the repository and what is required in the @Aggregate annotation?
What is the difference, if any, between the configurations below?
@Configuration
public class MyConfiguration {
@Bean
public Cache aggregateCache() {
return new WeakReferenceCache();
}
@Bean
public Repository<RequestEntity> myAggregateRepository(EventStore eventStore, Cache cache) {
return CachingEventSourcingRepository.builder(MyAggregate.class).cache(cache).eventStore(eventStore).build();
}
}
@Aggregate(cache = "aggregateCache", repository = "myAggregateRepository")
public class MyAggregate {
// state, CommandHandler, EventSourcingHandler
}
@Configuration
public class MyConfiguration {
@Bean
public Cache aggregateCache() {
return new WeakReferenceCache();
}
}
@Aggregate(cache = "aggregateCache")
public class MyAggregate {
// state, CommandHandler, EventSourcingHandler
}
@Configuration
public class MyConfiguration {
@Bean
public Cache aggregateCache() {
return new WeakReferenceCache();
}
@Bean
public Repository<RequestEntity> myAggregateRepository(EventStore eventStore, Cache cache) {
return EventSourcingRepository.builder(MyAggregate.class).cache(cache).eventStore(eventStore).build();
}
}
@Aggregate
public class MyAggregate {
// state, CommandHandler, EventSourcingHandler
}
I’m not sure if I fully understand the documentation here. It seems to me that they would all result in the same setup with a CachingEventSourcingRepository for MyAggregate with a cache associated.