本文整理汇总了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();
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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);
}
}
示例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();
}
示例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;
}
示例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));
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}