-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1단계] 애쉬 미션 제출합니다! #556
[1단계] 애쉬 미션 제출합니다! #556
Changes from all commits
68bceee
bc922fd
78bf086
26af54a
8be3acc
b1aeece
df98d05
bd4f051
fb5f423
e4c6b60
e982baf
b6cdfca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cache.com.example.cachecontrol; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.http.CacheControl; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
@Component | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 인터셉터는 최초 한 번만 생성하면 되므로, 다음과 같은 두 가지 방법으로 등록할 수 있어요.
애쉬는 왜 전자를 택했나요? (그냥 궁금증이예요~) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
진짜진짜 솔직하게 말하면 이유는 별로 생각 안 해봤읍니다. 그래서 이번 기회에 두 개가 어떻게 다른지 생각을 조금 해봤어요!
이 방식은 스프링의 IoC 컨테이너가 해당 객체를 관리해요. 장점:
단점:
이 방식은 개발자가 해당 객체를 직접 관리해요. 장점과 단점은 앞서 말한 이 중에서 당장 와닿는 장점은 역시 스프링이 해당 객체를 자동으로 관리해준다는 점인 것 같습니다. 우선은 이처럼 정리해볼 수 있을 것 같은데 아루는 어떻게 생각하시나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저라면
|
||
public class CacheInterceptor implements HandlerInterceptor { | ||
|
||
@Override | ||
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler) throws Exception { | ||
String cacheControl = CacheControl | ||
.noCache() | ||
.cachePrivate() | ||
.getHeaderValue(); | ||
|
||
response.setHeader(HttpHeaders.CACHE_CONTROL, cacheControl); | ||
|
||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
package cache.com.example.cachecontrol; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class CacheWebConfig implements WebMvcConfigurer { | ||
|
||
@Autowired | ||
private CacheInterceptor cacheInterceptor; | ||
|
||
@Override | ||
public void addInterceptors(final InterceptorRegistry registry) { | ||
registry.addInterceptor(cacheInterceptor).addPathPatterns("/"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
package cache.com.example.etag; | ||
|
||
import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.filter.ShallowEtagHeaderFilter; | ||
|
||
@Configuration | ||
public class EtagFilterConfiguration { | ||
|
||
// @Bean | ||
// public FilterRegistrationBean<ShallowEtagHeaderFilter> shallowEtagHeaderFilter() { | ||
// return null; | ||
// } | ||
@Bean | ||
public FilterRegistrationBean<ShallowEtagHeaderFilter> shallowEtagHeaderFilter() { | ||
FilterRegistrationBean<ShallowEtagHeaderFilter> filter = new FilterRegistrationBean<>(new ShallowEtagHeaderFilter()); | ||
|
||
filter.addUrlPatterns("/etag"); | ||
|
||
return filter; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 문제 해결되었나요? 현재 애쉬가 적어준 코드가 Git에 어느 부분인지를 확실히 모르겠어서 다시 재현하기 어렵네요. 제 생각에는 두 개가 같을 것이라고 생각되는데 🤔
getResource
의 인자로 같은 값이 들어갈 것이라고 생각되어요.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1-1단계를 구현하면서 생겼던 이슈라 코드의 구조가 많이 변화한 지금에서는 쉽게 재현되지가 않네요.
저도 두 개가 같을 거라고 생각하고 진행했는데 실제 디스플레이 되는 화면이 다르게 출력되어 궁금했던 부분이에요. 🤔
지금도 완벽하게 방법을 알고 에러를 핸들링했다기보다는 코드의 구조가 변화되며 재현이 안되는 얼렁뚱땅 해결(?)에 가까워서
조금 더 명확한 해결법이 뭐였을지, 더 정확히는 문제점이 뭐였을지 궁금한 상태인데요.
일단 이 부분은 일단 차차 구현하면서 같은 문제가 재현되는 걸 발견하게 되면 다시 한 번 질문 드리거나,
저만의 대답을 내어놓도록 하겠습니다.
살펴봐주셔서 감사해요~