我正在做一个二级哈泽尔广播缓存。缓存在findAll方法中非常正常,但是当我试图更新现有数据或添加新数据时,再次尝试使用findAll方法收集所有数据时,它会给出旧记录,而不是更新的记录。我在这里附上了我的密码。重点是当我试图使用findById方法获取数据时,它会从缓存本身提供更新的数据。我不想使用@CacheEvit。
@Override
@CachePut(cacheNames = "cache",key="#profileDTO.id")
public ProfileDTO save(ProfileDTO profileDTO) {
log.debug("Request to save Profile : {}", profileDTO);
Profile profile = profileMapper.toEntity(profileDTO);
profile = profileRepository.save(profile);
return profileMapper.toDto(profile);
}
/**
* Get all the profiles.
*
* @return the list of entities.
*/
@Override
@Cacheable(cacheNames = "cache")
public List<ProfileDTO> findAll() {
log.debug("Request to get all Profiles");
return profileRepository.findAll().stream()
.map(profileMapper::toDto)
.collect(Collectors.toCollection(LinkedList::new));
}
/**
* Get one profile by id.
*
* @param id the id of the entity.
* @return the entity.
*/
@Override
@Transactional(readOnly = true)
@Cacheable(cacheNames = { "cache" },key = "#id")
public Optional<ProfileDTO> findOne(Long id) {
log.debug("Request to get Profile : {}", id);
return profileRepository.findById(id)
.map(profileMapper::toDto);
}https://stackoverflow.com/questions/64640563
复制相似问题