skip to Main Content

I am trying to use single redis cache for storing the response of 2 Webservices- one is POST and one is GET. For GET service there is no request parameter against which I can store the response of Webservice in Redis, when I try to store it with hardcoded Key it gives me below error.

null key returned for cache operation (maybe you are using named params on classes without debug info?) Builder[public java.util.Map com.getResponse() throws com.adapter.framework.assetserviceadaptor.exception.ServiceExceptions] caches=[redis-cache] | key='#AssetCache' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'

This is how I am trying to store GET service response

@Cacheable(value="redis-cache",key ="#AssetCache")
public Map<String, AssetDetailBO> getAssetsResponse() throws COAssetServiceExceptions {
    try {
        log.info("---- CO_STAGE=[ Caching Service ] ---- ");
        return mergingBrokerageAndMutulFund(assetServiceImpl.getAssetResponse());
    } catch (ServiceExceptions e) {
        log.info("---- CO_STAGE=[ Exception while Calling Assets Adapter For COT ] ---- " 
        + e.getErrorMessage());
        throw e;
    }
}

This is how I am storing POST service response, this is working fine.

@Cacheable(value="redis-cache",key ="#customerId")
public CustomerDTO retriveCustomerdetails( String customerId, String modelId, 
  String requestId) throws COException {
CustomerInfo csDTO;
try {
    csDTO = csDTOAdapterImpl.
    getCustomerDetails(customerId);
} catch (Exception e) {
    e.printStackTrace();
}
return csDTO;
}

2

Answers


  1. You can use @Cacheable without the value and other properties like @Cacheable("all-students")

    Example:

    @GetMapping("/student/{id}")
    @Cacheable(value = "post-single", key = "#id")
    public Student findStudentById(@PathVariable String id) {
        System.out.println("Searching by ID  : " + id);
        return studentService.getStudentByID(id);
    }
    
    @GetMapping("/students")
    @Cacheable("all-students")
    public List<Student> getAllStudents() {
    
        List<Student> _ = new ArrayList<>();
        _.add(studentService.getStudentByID("1"));
        return _;
    }
    
    Login or Signup to reply.
  2. Set constant key without # like this:

    @Cacheable(value="redis-cache",key ="'AssetCache'")
    public Map<String, AssetDetailBO> getAssetsResponse() throws COAssetServiceExceptions {
        try {
            log.info("---- CO_STAGE=[ Caching Service ] ---- ");
            return mergingBrokerageAndMutulFund(assetServiceImpl.getAssetResponse());
        } catch (ServiceExceptions e) {
            log.info("---- CO_STAGE=[ Exception while Calling Assets Adapter For COT ] ---- " 
            + e.getErrorMessage());
            throw e;
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search