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


Java CacheControl.setMustRevalidate方法代碼示例

本文整理匯總了Java中javax.ws.rs.core.CacheControl.setMustRevalidate方法的典型用法代碼示例。如果您正苦於以下問題:Java CacheControl.setMustRevalidate方法的具體用法?Java CacheControl.setMustRevalidate怎麽用?Java CacheControl.setMustRevalidate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.core.CacheControl的用法示例。


在下文中一共展示了CacheControl.setMustRevalidate方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: show

import javax.ws.rs.core.CacheControl; //導入方法依賴的package包/類
@GET
@Path("{derivate}{path: (/[^?#]*)?}")
public Response show(@Context HttpServletRequest request, @Context Request jaxReq,
    @Context ServletContext context, @Context ServletConfig config) throws Exception {
    MCRContent content = getContent(request);
    String contentETag = content.getETag();
    Response.ResponseBuilder responseBuilder = null;
    EntityTag eTag = contentETag == null ? null : new EntityTag(contentETag);
    if (eTag != null) {
        responseBuilder = jaxReq.evaluatePreconditions(eTag);
    }
    if (responseBuilder == null) {
        responseBuilder = Response.ok(content.asByteArray(), MediaType.valueOf(content.getMimeType()));
    }
    if (eTag != null) {
        responseBuilder.tag(eTag);
    }
    if (content.isUsingSession()) {
        CacheControl cc = new CacheControl();
        cc.setPrivate(true);
        cc.setMaxAge(0);
        cc.setMustRevalidate(true);
        responseBuilder.cacheControl(cc);
    }
    return responseBuilder.build();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:27,代碼來源:MCRViewerResource.java

示例2: newResponseBuilder

import javax.ws.rs.core.CacheControl; //導入方法依賴的package包/類
final ResponseBuilder newResponseBuilder(final Status status, @Nullable final Object entity,
        @Nullable final GenericType<?> type) {
    Preconditions.checkState(this.context.variant != null);
    final ResponseBuilder builder = Response.status(status);
    if (entity != null) {
        builder.entity(type == null ? entity : new GenericEntity<Object>(entity, type
                .getType()));
        builder.variant(this.context.variant);
        final CacheControl cacheControl = new CacheControl();
        cacheControl.setNoStore(true);
        if ("GET".equalsIgnoreCase(this.request.getMethod())
                || "HEAD".equalsIgnoreCase(this.request.getMethod())) {
            builder.lastModified(this.context.lastModified);
            builder.tag(this.context.etag);
            if (isCachingEnabled()) {
                cacheControl.setNoStore(false);
                cacheControl.setMaxAge(0); // always stale, must revalidate each time
                cacheControl.setMustRevalidate(true);
                cacheControl.setPrivate(getUsername() != null);
                cacheControl.setNoTransform(true);
            }
        }
        builder.cacheControl(cacheControl);
    }
    return builder;
}
 
開發者ID:dkmfbk,項目名稱:knowledgestore,代碼行數:27,代碼來源:Resource.java

示例3: createCacheControl

import javax.ws.rs.core.CacheControl; //導入方法依賴的package包/類
/**
 * Converts a {@code Cache-Control} annotation to a {@code Cache-Control}
 * Jersey API object.
 *
 * @param annotation the annotation
 *
 * @return the Jersey API object
 *
 * @see javax.ws.rs.core.CacheControl
 * @see com.github.autermann.jersey.cache.CacheControl
 */
private CacheControl createCacheControl(
        com.github.autermann.jersey.cache.CacheControl annotation) {
    CacheControl cacheControl = new CacheControl();
    cacheControl.setPrivate(annotation._private() ||
                            annotation.privateFields().length > 0);
    cacheControl.getPrivateFields()
            .addAll(Arrays.asList(annotation.privateFields()));
    cacheControl.setMustRevalidate(annotation.mustRevalidate());
    cacheControl.setNoCache(annotation.noCache() ||
                            annotation.noCacheFields().length > 0);
    cacheControl.getNoCacheFields()
            .addAll(Arrays.asList(annotation.noCacheFields()));
    cacheControl.setNoStore(annotation.noStore());
    cacheControl.setNoTransform(annotation.noTransform());
    cacheControl.setProxyRevalidate(annotation.proxyRevalidate());
    cacheControl.setMaxAge(annotation.maxAge());
    cacheControl.setSMaxAge(annotation.sMaxAge());
    for (CacheControlExtension e : annotation.extensions()) {
        cacheControl.getCacheExtension().put(e.key(), e.value());
    }
    return cacheControl;
}
 
開發者ID:autermann,項目名稱:jersey-cache-control,代碼行數:34,代碼來源:CacheControlFilterFactory.java

示例4: fromString

import javax.ws.rs.core.CacheControl; //導入方法依賴的package包/類
@Override
public CacheControl fromString(final String value) {
    if (value == null) {
        return null;
    }

    final CacheControl result = new CacheControl();
    result.setPrivate(true);
    result.setNoTransform(false);

    for (final String directive : value.split(",\\s+")) {
        if (directive.startsWith("max-age=")) {
            result.setMaxAge(Integer.parseInt(directive.split("=")[1]));
        } else if (directive.equals("must-revalidate")) {
            result.setMustRevalidate(true);
        } else if (directive.equals("no-cache")) {
            result.setNoCache(true);
        } else if (directive.equals("no-store")) {
            result.setNoStore(true);
        } else if (directive.equalsIgnoreCase("no-transform")) {
            result.setNoTransform(true);
        } else if (directive.equals("private")) {
            result.setPrivate(true);
        } else if (directive.equals("proxy-revalidate")) {
            result.setProxyRevalidate(true);
        } else if (directive.equals("public")) {
            result.setPrivate(false);
        } else if (directive.startsWith("s-maxage=")) {
            result.setSMaxAge(Integer.parseInt(directive.split("=")[1]));
        }
    }

    return result;
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:35,代碼來源:MinijaxCacheControlDelegate.java

示例5: testSerializeFull

import javax.ws.rs.core.CacheControl; //導入方法依賴的package包/類
@Test
public void testSerializeFull() {
    final CacheControl c = new CacheControl();
    c.setMaxAge(100);
    c.setMustRevalidate(true);
    c.setNoCache(true);
    c.setNoStore(true);
    c.setNoTransform(false);
    c.setPrivate(true);
    c.setProxyRevalidate(true);
    c.setSMaxAge(200);
    assertEquals(
            "private, max-age=100, s-maxage=200, must-revalidate, no-cache, no-store, proxy-revalidate",
            d.toString(c));
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:16,代碼來源:CacheControlDelegateTest.java

示例6: createCacheControl

import javax.ws.rs.core.CacheControl; //導入方法依賴的package包/類
private static CacheControl createCacheControl(Cacheable cacheable) {
    CacheControl cacheControl = new CacheControl();
    cacheControl.setMaxAge(cacheable.maxAge());
    cacheControl.setMustRevalidate(cacheable.mustRevalidate());
    cacheControl.setNoCache(cacheable.noCache());
    cacheControl.setNoStore(cacheable.noStore());
    cacheControl.setNoTransform(cacheable.noTransform());
    cacheControl.setPrivate(cacheable.privateFlag());
    cacheControl.setProxyRevalidate(cacheable.proxyRevalidate());
    cacheControl.setSMaxAge(cacheable.sMaxAge());
    cacheControl.getNoCacheFields().addAll(Arrays.asList(cacheable.noCacheFields()));
    cacheControl.getPrivateFields().addAll(Arrays.asList(cacheable.privateFields()));
    return cacheControl;
}
 
開發者ID:Microbule,項目名稱:microbule,代碼行數:15,代碼來源:ContainerCacheFilter.java

示例7: download

import javax.ws.rs.core.CacheControl; //導入方法依賴的package包/類
@GET
@Path("/static/{name:.*}")
public Response download(@PathParam("name") final String name) throws Throwable {
    final InputStream stream = Root.class.getResourceAsStream(name);
    if (stream == null) {
        throw new WebApplicationException("No resource named " + name, Status.NOT_FOUND);
    }
    final String type = Data.extensionToMimeType(name);
    init(false, type, null, null);
    final CacheControl control = new CacheControl();
    control.setMaxAge(3600 * 24);
    control.setMustRevalidate(true);
    control.setPrivate(false);
    return newResponseBuilder(Status.OK, stream, null).cacheControl(control).build();
}
 
開發者ID:dkmfbk,項目名稱:knowledgestore,代碼行數:16,代碼來源:Root.java

示例8: getNoCacheResponseBuilder

import javax.ws.rs.core.CacheControl; //導入方法依賴的package包/類
public ResponseBuilder getNoCacheResponseBuilder(Response.Status status) {
  CacheControl cc = new CacheControl();
  cc.setNoCache(true);
  cc.setMaxAge(-1);
  cc.setMustRevalidate(true);

  return Response.status(status).cacheControl(cc);
}
 
開發者ID:hopshadoop,項目名稱:hopsworks,代碼行數:9,代碼來源:NoCacheResponse.java

示例9: getNoCacheCORSResponseBuilder

import javax.ws.rs.core.CacheControl; //導入方法依賴的package包/類
public ResponseBuilder getNoCacheCORSResponseBuilder(Response.Status status) {
  CacheControl cc = new CacheControl();
  cc.setNoCache(true);
  cc.setMaxAge(-1);
  cc.setMustRevalidate(true);
  return Response.status(status)
          .header("Access-Control-Allow-Origin", "*")
          .header("Access-Control-Allow-Methods", "GET")
          .cacheControl(cc);
}
 
開發者ID:hopshadoop,項目名稱:hopsworks,代碼行數:11,代碼來源:NoCacheResponse.java

示例10: buildCacheControl

import javax.ws.rs.core.CacheControl; //導入方法依賴的package包/類
public CacheControl buildCacheControl() {
    CacheControl cacheControl = new CacheControl();
    cacheControl.setNoTransform(false); // Default is true

    if (_maxAge.isPresent()) {
        cacheControl.setMaxAge((int) _maxAge.get().toSeconds());
    }

    if (_sharedMaxAge.isPresent()) {
        cacheControl.setSMaxAge((int) _maxAge.get().toSeconds());
    }

    if (_privateFields.size() > 0) {
        cacheControl.setPrivate(true);
        cacheControl.getPrivateFields().addAll(_privateFields);
    }

    if (_noCacheFields.size() > 0) {
        cacheControl.setNoCache(true);
        cacheControl.getNoCacheFields().addAll(_noCacheFields);
    }

    for (CacheControlFlag flag : _flags) {
        switch (flag) {
            case NO_CACHE:
                cacheControl.setNoCache(true);
                break;

            case NO_STORE:
                cacheControl.setNoStore(true);
                break;

            case MUST_REVALIDATE:
                cacheControl.setMustRevalidate(true);
                break;

            case PROXY_REVALIDATE:
                cacheControl.setProxyRevalidate(true);
                break;

            case NO_TRANSFORM:
                cacheControl.setNoTransform(true);
                break;

            case PRIVATE:
                cacheControl.setPrivate(true);
                break;

            case PUBLIC:
                // public is not directly supported by the CacheControl object, so use extension map
                cacheControl.getCacheExtension().put("public", "");
                break;

            default:
                checkState(false, "Unhandled cache control flag: " + flag);
                break;
        }
    }

    // Although the docs don't state it explicitly, both null and empty string get converted to a bare directive
    // for cache extensions.
    cacheControl.getCacheExtension().putAll(_cacheExtensions);
    return cacheControl;
}
 
開發者ID:bazaarvoice,項目名稱:dropwizard-caching-bundle,代碼行數:65,代碼來源:CacheControlConfigurationItem.java

示例11: getBinaryContent

import javax.ws.rs.core.CacheControl; //導入方法依賴的package包/類
/**
 * Get the binary content of a datastream
 *
 * @param rangeValue the range value
 * @return Binary blob
 * @throws IOException if io exception occurred
 */
protected Response getBinaryContent(final String rangeValue)
        throws IOException {
        final FedoraBinary binary = (FedoraBinary)resource();

        // we include an explicit etag, because the default behavior is to use the JCR node's etag, not
        // the jcr:content node digest. The etag is only included if we are not within a transaction.
        if (!session().isBatchSession()) {
            checkCacheControlHeaders(request, servletResponse, binary, session());
        }
        final CacheControl cc = new CacheControl();
        cc.setMaxAge(0);
        cc.setMustRevalidate(true);
        Response.ResponseBuilder builder;

        if (rangeValue != null && rangeValue.startsWith("bytes")) {

            final Range range = Range.convert(rangeValue);

            final long contentSize = binary.getContentSize();

            final String endAsString;

            if (range.end() == -1) {
                endAsString = Long.toString(contentSize - 1);
            } else {
                endAsString = Long.toString(range.end());
            }

            final String contentRangeValue =
                    String.format("bytes %s-%s/%s", range.start(),
                            endAsString, contentSize);

            if (range.end() > contentSize ||
                    (range.end() == -1 && range.start() > contentSize)) {

                builder = status(REQUESTED_RANGE_NOT_SATISFIABLE)
                        .header("Content-Range", contentRangeValue);
            } else {
                @SuppressWarnings("resource")
                final RangeRequestInputStream rangeInputStream =
                        new RangeRequestInputStream(binary.getContent(), range.start(), range.size());

                builder = status(PARTIAL_CONTENT).entity(rangeInputStream)
                        .header("Content-Range", contentRangeValue)
                        .header(CONTENT_LENGTH, range.size());
            }

        } else {
            @SuppressWarnings("resource")
            final InputStream content = binary.getContent();
            builder = ok(content);
        }


        // we set the content-type explicitly to avoid content-negotiation from getting in the way
        // getBinaryResourceMediaType will try to use the mime type on the resource, falling back on
        // 'application/octet-stream' if the mime type is syntactically invalid
        return builder.type(getBinaryResourceMediaType().toString())
                .cacheControl(cc)
                .build();

    }
 
開發者ID:fcrepo4,項目名稱:fcrepo4,代碼行數:70,代碼來源:ContentExposingResource.java


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