설명
AWS::Serverless::Api의 캐시 클러스터는 반복 응답을 재사용해 백엔드 호출을 줄일 수 있습니다. 캐시는 선택 사항이며, 최신 데이터나 사용자별 응답을 잘못 공유하지 않도록 사용 대상을 정해야 합니다.
잠재적 영향
캐시 가능한 요청이 많으면 캐시 미사용으로 백엔드 부하와 지연이 늘어날 수 있습니다.
해결 방법
캐시가 적합한 API에 CacheClusterEnabled: true를 설정하고 MethodSettings에서 필요한 메서드의 캐시를 켜세요. 캐시 키와 만료 시간도 함께 정하세요.
예시
예시는 GET 메서드의 캐시를 활성화합니다. 실제 API 정의와 응답별 캐시 키는 별도로 구성하세요.
변경 전
yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
TracingEnabled: true
변경 후
yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
TracingEnabled: true
CacheClusterEnabled: true
MethodSettings:
- ResourcePath: /*
HttpMethod: GET
CachingEnabled: true