use of org.hisp.dhis.common.cache.Cacheability in project dhis2-core by dhis2.
the class ContextUtils method configureResponse.
public void configureResponse(HttpServletResponse response, String contentType, CacheStrategy cacheStrategy, String filename, boolean attachment) {
CacheControl cacheControl;
if (contentType != null) {
response.setContentType(contentType);
}
if (CacheStrategy.RESPECT_SYSTEM_SETTING.equals(cacheStrategy)) {
String strategy = trimToNull((String) systemSettingManager.getSystemSetting(SettingKey.CACHE_STRATEGY));
cacheStrategy = strategy != null ? CacheStrategy.valueOf(strategy) : CacheStrategy.NO_CACHE;
}
if (CacheStrategy.CACHE_15_MINUTES.equals(cacheStrategy)) {
cacheControl = CacheControl.maxAge(15, TimeUnit.MINUTES);
} else if (CacheStrategy.CACHE_30_MINUTES.equals(cacheStrategy)) {
cacheControl = CacheControl.maxAge(30, TimeUnit.MINUTES);
} else if (CacheStrategy.CACHE_1_HOUR.equals(cacheStrategy)) {
cacheControl = CacheControl.maxAge(1, TimeUnit.HOURS);
} else if (CacheStrategy.CACHE_6AM_TOMORROW.equals(cacheStrategy)) {
cacheControl = CacheControl.maxAge(getSecondsUntilTomorrow(6), TimeUnit.SECONDS);
} else if (CacheStrategy.CACHE_TWO_WEEKS.equals(cacheStrategy)) {
cacheControl = CacheControl.maxAge(14, TimeUnit.DAYS);
} else {
cacheControl = CacheControl.noCache();
}
if (cacheStrategy != null && cacheStrategy != CacheStrategy.NO_CACHE) {
Cacheability cacheability = (Cacheability) systemSettingManager.getSystemSetting(SettingKey.CACHEABILITY);
if (cacheability.equals(Cacheability.PUBLIC)) {
cacheControl.cachePublic();
} else if (cacheability.equals(Cacheability.PRIVATE)) {
cacheControl.cachePrivate();
}
}
response.setHeader(HEADER_CACHE_CONTROL, cacheControl.getHeaderValue());
if (filename != null) {
String type = attachment ? "attachment" : "inline";
response.setHeader(HEADER_CONTENT_DISPOSITION, type + "; filename=\"" + filename + "\"");
}
}
Aggregations