Cache - hyunwoo-e/Spring GitHub Wiki
- ์๋ต ํค๋์ 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