Search code examples
javaspringcachingredisspring-boot

spring boot + redis cache + @Cacheable works for some methods and not others


I am using spring boot with redis for a cache, to improve application performance by reducing querying the RDBMS system. It works, as it caches the methods of another controller accurately but it does not cache the controller below:

@RequestMapping(method = RequestMethod.GET)
    @Cacheable("findByTaxOfficeId")
    private TaxPayerNameResponse findByTaxOfficeId(@RequestParam(required = true, value = "uid") String taxOfficeId) {
        StampDutyOffice stampDutyOffice = null;

The configuration looks the same for the working spring boot controller. A sample of a cached Controller method that works properly can be found below:

 @RequestMapping(value = "/stampdutyoffice", method = RequestMethod.GET)
    @Cacheable("getTaxPayerNameByTinIdOrJtbIdReqParam2")
    public TaxPayerNameResponse2 getTaxPayerNameByTinIdOrJtbIdReqParam2(@RequestParam(required = true, value = "uid") String tinIdOrJtbIdStampDutyOffice) {
        return getTaxPayerNameByTinIdOrJtbId2(tinIdOrJtbIdStampDutyOffice);
    }

What could be the issue please? Thanks in advance for helping out.


Solution

  • Your findByTaxOfficeId method is private, make it public