[GraphQL] cache를 활용해서 불필요한 요청 줄이기🔫

이주희·2022년 8월 13일
0

GraphQL

목록 보기
1/5
post-thumbnail

ApolloClient InMemoryCache

ApolloClient에서 기본적으로 제공하는 클래스인 InMemoryCache를 사용하면,
동일한 쿼리 요청을 보낼 때 GraphQL server에 새롭게 요청하지 않고, 이전에 서버에서 가져와 Apollo Client cache에 저장되어 있는 데이터를 가져오게 설정할 수 있다.

사용 방법
컴포넌트 밖에서 InMemoryCache 객체를 만들고 ApolloClient를 생성할 때 전달한다.

const APOLLO_CACHE = new InMemoryCache();
export default function ApolloSetting(props) {
  
  ...
  
const client = new ApolloClient({
  
 	 ...
  
    cache: APOLLO_CACHE,
  });
  
  ...
  
profile
🍓e-juhee.tistory.com 👈🏻 이사중

0개의 댓글