restx.http.CacheControl Maven / Gradle / Ivy
package restx.http;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import restx.RestxResponse;
/**
* Date: 22/5/14
* Time: 18:47
*/
public class CacheControl {
public static final CacheControl MUST_REVALIDATE = new CacheControl(-1, ImmutableList.of("must-revalidate"));
private final int expires;
private final ImmutableList cacheControl;
public CacheControl(int expires, ImmutableList cacheControl) {
this.expires = expires;
this.cacheControl = cacheControl;
}
public int getExpires() {
return expires;
}
public ImmutableList getCacheControl() {
return cacheControl;
}
@Override
public String toString() {
return "CacheControl{" +
"expires=" + expires +
", cacheControl=" + cacheControl +
'}';
}
public void writeTo(RestxResponse resp) {
resp.setHeader("Expires", String.valueOf(expires));
resp.setHeader("Cache-Control", Joiner.on(", ").join(cacheControl));
}
}