I am trying to add a cache on a component bean and spring is not creating the proxy class. If I put the @Cacheable on the repo then it works just fine. I'm verifying this currently just by looking inside the cacheManager after each invocation. What am I doing wrong here??
@Configuration
@EnableCaching
public class CacheConfig {
@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager("clientids");
}
}
@Service
@RequiredArgsConstructor
public class CacheDelegator {
private final RepoUser getFromRepo;
public ClientReference getId(String email) {
return getFromRepo.getFromRepo(email).orElseThrow(() ->
new ClientNotFoundException(ExceptionType.NOT_FOUND));
}
}
@Component
@RequiredArgsConstructor
public class RepoUser {
private final ClientRepository repository;
@Cacheable("clientids")
Optional<ClientReference> getFromRepo(String email) {
return repository.findClientIdByEmail(email);
}
}
@Repository
public interface ClientRepository extends JpaRepository<ClientReference, Long> {
Optional<ClientReference> findClientIdByEmail(String email);
}
I know this is a roundabout way of doing it. I'm trying to understand how the cache interceptors are being created though.
As per Deinum above. My method needed to be public.