Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
Spring Boot Start Cache Not triggering

I am running a spring boot 1.5.2 app. I wanted to add caching to my service methods I have added the spring-boot-starter-cache maven dependency and I am using the @ Cacheable annotations but it is not taking effect I created my service beans in a @ Configuration class - here is an example

@Bean(name = "policyService")
public IPolicyService policyService() {
    policyService = new PolicyServiceImpl();
    return policyService;
}

Here is an example of my service method

@Cacheable(value="policiesCache")
    public List<PolicyDBO> findAllPolicies() {
        LOG.info("Entered findAllPolicies");

        List<PolicyDBO> policyList = policyRespoitory.findAll();

        LOG.info("Exiting findAllPolicies");
        return policyList;
    }

My repoistory interface method is as follows

@Repository
public interface PolicyRepository extends CrudRepository<PolicyDBO, Long>{

    /** Find policy by id **/
    PolicyDBO findById(Long policyId);
}

Whenever I call this service method from a RestController - the caching is never triggered - it looks like it is not setup properly

Any ideas what I can do to get caching setup correctly?

Thanks Damien

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Assuming that caching is active, Spring Caching is working correctly, but not as you expect. @Cacheable caches arguments against results.

In your case, the cache is storing no arguments against the result of List<PolicyDBO>.

However when you call findById, the cache doesn't find anything against an argument of Long and so doesn't return a cached result.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!