當前位置: 首頁>>代碼示例>>Java>>正文


Java CacheControl.isProxyRevalidate方法代碼示例

本文整理匯總了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();
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:38,代碼來源:MinijaxCacheControlDelegate.java

示例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);
}
 
開發者ID:bazaarvoice,項目名稱:dropwizard-caching-bundle,代碼行數:49,代碼來源:ResponseCache.java


注:本文中的javax.ws.rs.core.CacheControl.isProxyRevalidate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。