redisson 이용 방법. 특히 RMapCache를 이용해 Write-Behind하기
config가 정말 중요했다.
@Configuration
@AllArgsConstructor
public class CacheConfig {
private final RedissonClient redissonClient;
private final PhotoRepository photoRepository;
@Bean
public RMapCache<String, Photo> photoRMapCache() {
final RMapCache<String, Photo> photoRMapCache
= redissonClient.getMapCache("photos", MapCacheOptions.<String, Photo>defaults()
.writer(getPhotoMapWriter())
.writeMode(MapOptions.WriteMode.WRITE_BEHIND)
.writeBehindBatchSize(100)
.writeBehindDelay(1000));
return photoRMapCache;
}
private MapWriter<String, Photo> getPhotoMapWriter() {
return new MapWriter<String, Photo>() {
@Override
public void write(Map<String, Photo> map) {
map.forEach((k, v) -> {
photoRepository.save(v);
});
}
@Override
public void delete(Collection<String> keys) {
// TODO : 2024.01.31 url로 삭제 시 삭제되게 하고싶은데 이상함
keys.stream().forEach(key -> {
photoRepository.deleteByUrl(key);
});
}
};
}
}
### 내일 할 것
- 프론트와 연결
- 오류 수정
- 배포