当前位置: 首页>>代码示例>>Java>>正文


Java CacheControl.setMaxAge方法代码示例

本文整理汇总了Java中javax.ws.rs.core.CacheControl.setMaxAge方法的典型用法代码示例。如果您正苦于以下问题:Java CacheControl.setMaxAge方法的具体用法?Java CacheControl.setMaxAge怎么用?Java CacheControl.setMaxAge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.core.CacheControl的用法示例。


在下文中一共展示了CacheControl.setMaxAge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: cacheAwareResponse

import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
private Response cacheAwareResponse(
    Request request, String entity, EntityTag etag, Date lastModified, int maxAge
) {

  final Response.ResponseBuilder builderLastMod = request.evaluatePreconditions(lastModified);
  if (builderLastMod != null) {
    return builderLastMod.build();
  }

  final Response.ResponseBuilder builderEtag = request.evaluatePreconditions(etag);
  if (builderEtag != null) {
    return builderEtag.build();
  }

  final CacheControl cc = new CacheControl();
  cc.setMaxAge(maxAge);

  return Response.ok(entity)
      .tag(etag)
      .lastModified(lastModified)
      .cacheControl(cc)
      .build();
}
 
开发者ID:dehora,项目名称:outland,代码行数:24,代码来源:OpenApiDiscoveryResource.java

示例2: 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

示例3: 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

示例4: retrieveSomeSamples

import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@Override
public Response retrieveSomeSamples(final String ids) throws Exception {

	Integer[] keys = Util.parseAsLongArray(ids);

	List<SampleBean> data = new ArrayList<SampleBean>();

	SampleBean one = null;
	for (int i = 0; i < keys.length; i++)
	{
		one = new SampleBean(keys[i], 4, "test1", "test1");
		data.add(one);
	}

	CacheControl cc = new CacheControl();
	cc.setMaxAge(30000);

	GenericEntity<List<SampleBean>> entity =
			new GenericEntity<List<SampleBean>>(data) {
			};

	ResponseBuilder builder = Response.ok(entity);
	builder.cacheControl(cc);
	return builder.build();
}
 
开发者ID:Appverse,项目名称:appverse-server,代码行数:26,代码来源:MockResource.java

示例5: index

import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
/**
 * Show a photo.
 * @param num ID of the user
 * @return PNG
 * @throws IOException If fails
 */
@GET
@Path("/{id : \\d+}.png")
@Produces("image/png")
public Response index(@PathParam("id") final String num)
    throws IOException {
    final URN urn = URN.create(String.format("urn:aintshy:%s", num));
    final byte[] png = this.base().human(urn).profile().photo();
    if (png == null) {
        throw new WebApplicationException(
            Response.seeOther(
                URI.create("http://img.aintshy.com/no-photo.png")
            ).build()
        );
    }
    final CacheControl cache = new CacheControl();
    cache.setMaxAge((int) TimeUnit.HOURS.toSeconds(1L));
    cache.setPrivate(false);
    return Response.ok(new ByteArrayInputStream(png))
        .cacheControl(cache)
        .type("image/png")
        .build();
}
 
开发者ID:aintshy,项目名称:hub,代码行数:29,代码来源:PhotoRs.java

示例6: 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

示例7: filter

import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@Override
public void filter(final ContainerRequestContext req, final ContainerResponseContext res) throws IOException {

    if (req.getMethod().equals(GET)) {
        final CacheControl cc = new CacheControl();
        cc.setMaxAge(cacheAge);
        res.getHeaders().add(CACHE_CONTROL, cc);
    }
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:10,代码来源:CacheControlFilter.java

示例8: getVersionInfo

import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@GET
@Path("version")
@Produces(MediaType.APPLICATION_JSON)
public Response getVersionInfo() {

	CacheControl cc = new CacheControl();
	cc.setMaxAge(60 * 60 * 24); // seconds
	cc.setPrivate(true);

	return Response
               .status(Response.Status.OK)
               .cacheControl(cc)
               .entity(graphene.getVersionInfo())
               .build();
   }
 
开发者ID:Lambda-3,项目名称:Graphene,代码行数:16,代码来源:AdminResource.java

示例9: 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

示例10: 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

示例11: getMetaDataSG1V1

import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@LogDuration(limit = 50)
public Response getMetaDataSG1V1(UriInfo uriInfo, Request request) {
    EventsMetadataRepresentation em  = new EventsMetadataRepresentation("", uriInfo);
    CacheControl cc = new CacheControl();
    int maxAge = 4 * 7 * 24 * 60 * 60;
    cc.setMaxAge(maxAge);

    return Response.ok()
            .entity(em)
            .cacheControl(cc).expires(Date.from(CurrentTime.now().plusSeconds(maxAge)))
            .type("application/hal+json;concept=metadata;v=1")
            .build();
}
 
开发者ID:psd2-in-a-box,项目名称:mid-tier,代码行数:14,代码来源:CustomerEventFeedMetadataServiceExposure.java

示例12: build

import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
/**
 * Build a response given a concrete request. If the request contain an <code>if-modified-since</code> or
 * <code>if-none-match</code> header this will be checked against the entity given to the builder returning
 * a response with status not modified if appropriate.
 */
public Response build(Request req) {
    EntityTag eTag = new EntityTag(Integer.toString(entity.hashCode()));
    Date lastModified = entity instanceof AbstractAuditable ? ((AbstractAuditable) entity).getLastModifiedTime() : Date.from(Instant.now());
    Response.ResponseBuilder notModifiedBuilder = req.evaluatePreconditions(lastModified, eTag);
    if (notModifiedBuilder != null) {
        return notModifiedBuilder.build();
    }

    Map<String, String> parameters = new ConcurrentHashMap<>();
    if (name != null) {
        parameters.put("concept", name);
    }
    if (version != null) {
        parameters.put("v", version);
    }
    MediaType type = getMediaType(parameters, supportsContentTypeParameter);

    Response.ResponseBuilder b = Response.ok(mapper.apply(entity))
            .type(type)
            .tag(eTag)
            .lastModified(lastModified);

    if (maxAge != null) {
        CacheControl cc = new CacheControl();
        cc.setMaxAge(maxAge);
        b.cacheControl(cc).expires(Date.from(Instant.now().plusSeconds(maxAge)));
    }

    return b.build();
}
 
开发者ID:psd2-in-a-box,项目名称:mid-tier,代码行数:36,代码来源:EntityResponseBuilder.java

示例13: getProvince

import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@GET
@Path("province")
@Produces(MediaType.APPLICATION_JSON)
public Response getProvince(){
	BaseResponse<List<Province>> entity = new BaseResponse<>(areaManager.getProvince());
	CacheControl cacheControl = new CacheControl();
	cacheControl.setMaxAge((int)TimeUnit.DAYS.toSeconds(1)*365);
	return Response.status(200)
			.cacheControl(cacheControl)
			.entity(entity).build();
}
 
开发者ID:ChineseLincoln,项目名称:JerseyRestful,代码行数:12,代码来源:AreaService.java

示例14: getCity

import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@GET
@Path("city")
@Produces(MediaType.APPLICATION_JSON)
public Response getCity(@QueryParam(value = "provinceId") String provinceId){
	BaseResponse<List<City>> entity = new BaseResponse<>(areaManager.getCity(provinceId));
	CacheControl cacheControl = new CacheControl();
	cacheControl.setMaxAge((int)TimeUnit.DAYS.toSeconds(1)*365);
	return Response.status(200)
			.cacheControl(cacheControl)
			.entity(entity).build();
}
 
开发者ID:ChineseLincoln,项目名称:JerseyRestful,代码行数:12,代码来源:AreaService.java

示例15: getCounty

import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@GET
@Path("county")
@Produces(MediaType.APPLICATION_JSON)
public Response getCounty(@QueryParam(value = "cityId") String cityId){
	BaseResponse<List<County>> entity = new BaseResponse<>(areaManager.getCounty(cityId));
	CacheControl cacheControl = new CacheControl();
	cacheControl.setMaxAge((int)TimeUnit.DAYS.toSeconds(1)*365);
	return Response.status(200)
			.cacheControl(cacheControl)
			.entity(entity).build();
}
 
开发者ID:ChineseLincoln,项目名称:JerseyRestful,代码行数:12,代码来源:AreaService.java


注:本文中的javax.ws.rs.core.CacheControl.setMaxAge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。