本文整理汇总了Java中org.springframework.http.CacheControl类的典型用法代码示例。如果您正苦于以下问题:Java CacheControl类的具体用法?Java CacheControl怎么用?Java CacheControl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CacheControl类属于org.springframework.http包,在下文中一共展示了CacheControl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addResourceHandlers
import org.springframework.http.CacheControl; //导入依赖的package包/类
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
final CacheControl oneYear = CacheControl.maxAge(365, TimeUnit.DAYS).cachePublic();
registry.addResourceHandler("/favicon.ico")
.addResourceLocations("/favicon.ico")
.setCacheControl(oneYear);
registry.addResourceHandler("/static/**")
.addResourceLocations("/static/")
.setCacheControl(oneYear);
registry.addResourceHandler("/frontend/**")
.addResourceLocations("/frontend/")
.setCacheControl(oneYear);
}
示例2: addResourceHandlers
import org.springframework.http.CacheControl; //导入依赖的package包/类
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/app/**")
.addResourceLocations("classpath:/app/");
CacheControl cacheControl = CacheControl
.maxAge(365, TimeUnit.DAYS)
.cachePublic();
registry.addResourceHandler("/assets/**")
.addResourceLocations("classpath:/assets/")
.setCacheControl(cacheControl);
if (!registry.hasMappingForPattern("/webjars/**")) {
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/")
.setCacheControl(cacheControl);
}
}
示例3: newResponse
import org.springframework.http.CacheControl; //导入依赖的package包/类
private final ResponseEntity.BodyBuilder newResponse(final HttpStatus status, final String etag)
{
ResponseEntity.BodyBuilder response = ResponseEntity.status(status)
.eTag(etag)
.cacheControl(CacheControl.maxAge(cacheMaxAgeSec, TimeUnit.SECONDS));
final String adLanguage = getJSONOptions().getAD_Language();
if (adLanguage != null && !adLanguage.isEmpty())
{
final String contentLanguage = ADLanguageList.toHttpLanguageTag(adLanguage);
response.header(HttpHeaders.CONTENT_LANGUAGE, contentLanguage);
response.header(HttpHeaders.VARY, HttpHeaders.ACCEPT_LANGUAGE); // advice browser to include ACCEPT_LANGUAGE in their caching key
}
return response;
}
示例4: addResourceHandlers
import org.springframework.http.CacheControl; //导入依赖的package包/类
/**
* Needed to serve the UI-part of swagger
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
// Set cache timeout for static resources to reduce resource burden on application
registry.addResourceHandler("/static/**")
.addResourceLocations("/static/")
.setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS))
.resourceChain(false)
.addResolver(new VersionResourceResolver().addContentVersionStrategy("/**"));
}
示例5: setResponse
import org.springframework.http.CacheControl; //导入依赖的package包/类
private static void setResponse( HttpServletResponse response, int statusCode, String message )
{
response.setStatus( statusCode );
response.setContentType( CONTENT_TYPE_TEXT );
response.setHeader( HEADER_CACHE_CONTROL, CacheControl.noStore().getHeaderValue() );
PrintWriter writer = null;
try
{
writer = response.getWriter();
writer.println( message );
writer.flush();
}
catch ( IOException ex )
{
// Ignore
}
finally
{
IOUtils.closeQuietly( writer );
}
}
示例6: getObject
import org.springframework.http.CacheControl; //导入依赖的package包/类
@RequestMapping( value = "/{uid}", method = RequestMethod.GET )
public @ResponseBody RootNode getObject(
@PathVariable( "uid" ) String pvUid,
@RequestParam Map<String, String> rpParameters,
HttpServletRequest request, HttpServletResponse response ) throws Exception
{
User user = currentUserService.getCurrentUser();
if ( !aclService.canRead( user, getEntityClass() ) )
{
throw new ReadAccessDeniedException( "You don't have the proper permissions to read objects of this type." );
}
List<String> fields = Lists.newArrayList( contextService.getParameterValues( "fields" ) );
List<String> filters = Lists.newArrayList( contextService.getParameterValues( "filter" ) );
if ( fields.isEmpty() )
{
fields.add( ":all" );
}
response.setHeader( ContextUtils.HEADER_CACHE_CONTROL, CacheControl.noCache().cachePrivate().getHeaderValue() );
return getObjectInternal( pvUid, rpParameters, filters, fields, user );
}
示例7: getBadge
import org.springframework.http.CacheControl; //导入依赖的package包/类
@RequestMapping(value = "/{account}/{projectName}/{branchName}.svg")
public ResponseEntity<String> getBadge(@PathVariable String account, @PathVariable String projectName, @PathVariable String branchName) throws Exception {
QBuild b = QBuild.build;
Page<Build> buildPage = buildRepository.findAll(b.branch.name.eq(branchName).and(b.branch.project.account.eq(account)).and(b.branch.project.name.eq(projectName)), new QPageRequest(0, 2, b.number.desc()));
if (buildPage.getTotalPages() == 0)
throw new BadgeUnknownException();
Build latest = buildPage.getContent().get(0);
long current = System.currentTimeMillis();
HttpHeaders headers = new HttpHeaders(); // see #7
headers.setExpires(current);
headers.setDate(current);
return ResponseEntity
.ok()
.headers(headers)
.cacheControl(CacheControl.noCache())
.lastModified(current)
.eTag(Long.toString(latest.getId()))
.body(FreeMarkerTemplateUtils.processTemplateIntoString(configurer.getConfiguration().getTemplate("badge/mybadge.ftl"), latest));
}
示例8: downloadFile
import org.springframework.http.CacheControl; //导入依赖的package包/类
/**
* Download a file from the GridFS / MongoDB by a given filename.
*/
@RequestMapping(value = "/files/**")
public ResponseEntity<?> downloadFile(HttpServletRequest request) {
String completePath =
(String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
String fileName = completePath.replaceFirst("/public/files", "");
// find file in grid fs / mongo db
GridFSDBFile gridFsFile = this.fileService.findFile(fileName);
if (gridFsFile == null) {
return ResponseEntity.notFound().build();
}
HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.CONTENT_DISPOSITION,
"filename=" + removeFolders(gridFsFile.getFilename()));
// Return Status 200 or 304 if not modified
return ResponseEntity.ok()
.headers(headers)
.contentLength(gridFsFile.getLength())
.cacheControl(CacheControl.maxAge(0, TimeUnit.MILLISECONDS).mustRevalidate()
.cachePrivate().cachePublic())
.eTag(String.valueOf(gridFsFile.getUploadDate().getTime()))
.lastModified(gridFsFile.getUploadDate().getTime())
.contentType(MediaType.parseMediaType(gridFsFile.getContentType()))
.body(new InputStreamResource(gridFsFile.getInputStream()));
}
示例9: findPreviousStudyVersions
import org.springframework.http.CacheControl; //导入依赖的package包/类
/**
* Get the previous 10 versions of the study attachment metadata.
*
* @param studyId The id of the study
* @param filename The filename of the attachment
* @param limit like page size
* @param skip for skipping n versions
*
* @return A list of previous study versions
*/
@RequestMapping("/studies/{studyId}/attachments/{filename:.+}/versions")
public ResponseEntity<?> findPreviousStudyVersions(@PathVariable String studyId,
@PathVariable String filename,
@RequestParam(name = "limit", defaultValue = "10") Integer limit,
@RequestParam(name = "skip", defaultValue = "0") Integer skip) {
List<StudyAttachmentMetadata> studyAttachmentVersions = studyAttachmentVersionsService
.findPreviousStudyAttachmentVersions(studyId, filename, limit, skip);
if (studyAttachmentVersions == null) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok()
.cacheControl(CacheControl.noStore())
.body(studyAttachmentVersions);
}
示例10: addResourceHandlers
import org.springframework.http.CacheControl; //导入依赖的package包/类
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
/*registry.addResourceHandler(UploadViewController.CONTROLLER_PATH+"/**")
.setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS));*/
//默认把上传目录映射
if(siteConfig.getUpload().isFileStorePathToResourceHandler()){
registry.addResourceHandler(BootWebUtils.CONTROLLER_PREFIX+"/upload/**")
.addResourceLocations("file:"+FileUtils.convertDir(siteConfig.getUpload().getFileStorePath()))
.setCacheControl(CacheControl.maxAge(siteConfig.getUpload().getResourceCacheInDays(), TimeUnit.DAYS));
}
List<ResourceHandlerConfig> resourceHandlers = this.jfishBootConfig.getMvc().getResourceHandlers();
resourceHandlers.forEach(res->{
registry.addResourceHandler(res.getPathPatterns())
.addResourceLocations(res.getLocations())
.setCacheControl(CacheControl.maxAge(res.getCacheInDays(), TimeUnit.DAYS));
});
}
示例11: badgeFor
import org.springframework.http.CacheControl; //导入依赖的package包/类
/**
* Creates a SVG badge for a project with a given {@link ReleaseStatus}.
*
* @param projectId
* @param releaseStatus
* @return
* @throws IOException
*/
private ResponseEntity<byte[]> badgeFor(String projectId, ReleaseStatus releaseStatus) throws IOException {
Project project = service.getProject(projectId);
if (project == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
Optional<ProjectRelease> gaRelease = getRelease(project.getProjectReleases(),
projectRelease -> projectRelease.getReleaseStatus() == releaseStatus);
if (!gaRelease.isPresent()) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
byte[] svgBadge = versionBadgeService.createSvgBadge(project, gaRelease.get());
return ResponseEntity.ok().eTag(gaRelease.get().getVersion()).cacheControl(CacheControl.maxAge(1L, TimeUnit.HOURS))
.body(svgBadge);
}
示例12: serviceCapabilitiesFor
import org.springframework.http.CacheControl; //导入依赖的package包/类
private ResponseEntity<String> serviceCapabilitiesFor(
InitializrMetadataVersion version, MediaType contentType) {
String appUrl = generateAppUrl();
String content = getJsonMapper(version).write(metadataProvider.get(), appUrl);
return ResponseEntity.ok().contentType(contentType).eTag(createUniqueId(content))
.cacheControl(CacheControl.maxAge(7, TimeUnit.DAYS)).body(content);
}
示例13: dependenciesFor
import org.springframework.http.CacheControl; //导入依赖的package包/类
private ResponseEntity<String> dependenciesFor(InitializrMetadataVersion version,
String edorasoneVersion) {
InitializrMetadata metadata = metadataProvider.get();
Version v = edorasoneVersion != null ? Version.parse(edorasoneVersion)
: Version.parse(metadata.getEdorasoneVersions().getDefault().getId());
DependencyMetadata dependencyMetadata = dependencyMetadataProvider.get(metadata,
v);
String content = new DependencyMetadataV21JsonMapper().write(dependencyMetadata);
return ResponseEntity.ok().contentType(version.getMediaType())
.eTag(createUniqueId(content))
.cacheControl(CacheControl.maxAge(7, TimeUnit.DAYS)).body(content);
}
示例14: getBootstrap
import org.springframework.http.CacheControl; //导入依赖的package包/类
/**
* Gets bootstrap.
*
* @return the bootstrap
*/
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<Bootstrap> getBootstrap() {
return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(2, TimeUnit.HOURS))
.body(bootstrap);
}
示例15: addResourceHandlers
import org.springframework.http.CacheControl; //导入依赖的package包/类
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/assets/**").addResourceLocations("file:node_modules/").setCacheControl(CacheControl.maxAge(1, TimeUnit.DAYS));
registry.addResourceHandler("/js/**").addResourceLocations("file:src/main/app/js/").setCacheControl(CacheControl.maxAge(1, TimeUnit.DAYS));
registry.addResourceHandler("/css/**").addResourceLocations("file:src/main/app/css/").setCacheControl(CacheControl.maxAge(1, TimeUnit.DAYS));
registry.addResourceHandler("/images/**").addResourceLocations("file:src/main/resources/static/images/").setCacheControl(CacheControl.maxAge(1, TimeUnit.DAYS));
super.addResourceHandlers(registry);
}