I just tried to store the result of items in the cache and all went well except the key.
The SimpleKeyGenerator usually save the object or the result based on the arguments and in my case, I want to store an object in the cache and the key should be an attribute of the object inside the list here is an example.
public class Item{
private Long id;
private Long reference;
private Integer status;
//setter and getter
}
public interface ItemRepository extends JpaRepository<Long,Item>{
@Cachable("items")
List<Item> findByReferenceAndStatus(Long reference, Integer status);
}
now I want to store each object in the cache based on item.id, I know we can use the key attribute of the annotation but how can I access the Id for each item using SpEL. Unfortunately, create custom key generator will not help because all based on the arguments, target class and method.
any recommendations?