本文整理汇总了Java中javax.ws.rs.core.CacheControl.isProxyRevalidate方法的典型用法代码示例。如果您正苦于以下问题:Java CacheControl.isProxyRevalidate方法的具体用法?Java CacheControl.isProxyRevalidate怎么用?Java CacheControl.isProxyRevalidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.CacheControl
的用法示例。
在下文中一共展示了CacheControl.isProxyRevalidate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toString
import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@Override
public String toString(final CacheControl value) {
if (value == null) {
return null;
}
final StringBuilder b = new StringBuilder();
if (value.isPrivate()) {
b.append("private");
} else {
b.append("public");
}
if (value.getMaxAge() >= 0) {
b.append(", max-age=").append(value.getMaxAge());
}
if (value.getSMaxAge() >= 0) {
b.append(", s-maxage=").append(value.getSMaxAge());
}
if (value.isMustRevalidate()) {
b.append(", must-revalidate");
}
if (value.isNoCache()) {
b.append(", no-cache");
}
if (value.isNoStore()) {
b.append(", no-store");
}
if (value.isNoTransform()) {
b.append(", no-transform");
}
if (value.isProxyRevalidate()) {
b.append(", proxy-revalidate");
}
return b.toString();
}
示例2: isCacheAcceptable
import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
/**
* Test if this request allows a specific cached response to be returned.
*
* @param request the request context
* @param now instant that represents the current time
* @param response response to check
* @return true if the cached response can be returned, false if the request must be re-validated with the origin
* server
*/
private static boolean isCacheAcceptable(CacheRequestContext request, DateTime now, CachedResponse response) {
// NOTE: Do not check that the expiration time is before NOW here. That is verified later against the max-stale
// cache-control option.
DateTime responseDate = response.getDate();
DateTime responseExpires = response.getExpires().get();
if (responseExpires.isBefore(responseDate)) {
return false;
}
RequestCacheControl requestCacheControl = request.getCacheControl();
if (requestCacheControl.getMaxAge() > 0) {
int age = Seconds.secondsBetween(responseDate, now).getSeconds();
if (age > requestCacheControl.getMaxAge()) {
return false;
}
}
if (requestCacheControl.getMinFresh() >= 0 || requestCacheControl.getMaxStale() >= 0) {
int freshness = Seconds.secondsBetween(now, responseExpires).getSeconds();
if (requestCacheControl.getMinFresh() >= 0 && freshness < requestCacheControl.getMinFresh()) {
return false;
}
if (requestCacheControl.getMaxStale() >= 0) {
CacheControl responseCacheControl = response.getCacheControl().orNull();
boolean responseMustRevalidate = responseCacheControl != null && (responseCacheControl.isProxyRevalidate() || responseCacheControl.isMustRevalidate());
if (!responseMustRevalidate) {
return freshness >= -requestCacheControl.getMaxStale();
}
}
}
return !responseExpires.isBefore(now);
}