-
Notifications
You must be signed in to change notification settings - Fork 0
Cache
hyunwoo9301 edited this page Aug 7, 2017
·
8 revisions
- 응답 헤더의 cache-control에 no-store 옵션을 사용한 경우 캐시되지 않음
- 캐시된 데이터의 만료일자(expire)/만료시간(max-age)가 남은 경우 최신상태로 간주
- 캐시가 최신이 아닐 경우 유효성 검사를 요청, 304 리턴시 만료일자/시간을 업데이트
응답 헤더의 캐시 지시자는 cache-control을 사용(pragma, expires는 호환, 싱크 문제가 있음)
- no-store: 요청이나 응답을 저장하지 않음
- no-cache
- Request - 프록시를 거쳐 실 서버까지 도달하게 함
- Response - 캐시하고 있으나 유효성 검사를 강제함
정적데이터(js, css, image 등)은 응답 헤더에 Last-Modified를 가지고 있어 캐시할 수 있음
- Apache에서 캐시할 수 있음
- Spring에서 캐시하기 위해서는 Servlet Context 파일에 mvc:resources를 통해 지정
<mvc:resources mapping="/js/**" location="/js/" cache-period="86400"/>
<mvc:resources mapping="/style/**" location="/style/" cache-period="86400"/>
<mvc:resources mapping="/image/**" location="/image/" cache-period="31556926"/>
- cache-period
- Specifies the cache period for the resources served by this resource handler, in seconds.
- The default is to not send any cache headers but rather to rely on last-modified timestamps only.
- Set this to 0 in order to send cache headers that prevent caching, or to a positive number of seconds in order to send cache headers with the given max-age value.
PHP, ASP, JSP등 동적으로 생성된 컨텐츠는 Last-Modified, Cache-Control 등의 정보가 없어 손쉽게 캐시할 수 없음
스프링에서 캐시를 제어하기 위해서는 Servlet Context 파일에 WebContentInterceptor를 설정해야 한다
- /api 이하 cache, 사진은 예외적으로 24시간 동안 cache
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/api/**/*"/>
<bean class="org.springframework.web.servlet.mvc.WebContentInterceptor">
<property name="cacheSeconds" value="0"/>
<property name="cacheMappings">
<props>
<prop key="/api/photo/**">86400</prop>
</props>
</property>
</bean>
</mvc:interceptor>
</mvc-interceptors>
- Controller에 Cache를 설정하는 방법 Spring MVC Cache Control
-
Spring
-
Web
-
Security
-
ETC