-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardService.java
More file actions
38 lines (31 loc) · 1.06 KB
/
BoardService.java
File metadata and controls
38 lines (31 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package org.dailystudio.springbootstudy.service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dailystudio.springbootstudy.domain.Board;
import org.dailystudio.springbootstudy.repository.BoardRepository;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service
@Slf4j
@RequiredArgsConstructor
public class BoardService {
private final BoardRepository boardRepository;
@CacheEvict(value = "contents", allEntries = true)
public void saveContent(String content) {
Board board = new Board(content);
boardRepository.save(board);
}
@Cacheable(value = "contents")
public List<String> fetchContents() {
logCache();
return boardRepository.findAll().stream()
.map(Board::getContent)
.collect(Collectors.toList());
}
private void logCache() {
log.info("new cache.");
}
}