Rework caching configuration

Closes gh-401
This commit is contained in:
Stephane Nicoll 2017-09-15 13:29:45 +02:00
parent 41a4b13af1
commit cf93d5ddef
5 changed files with 12 additions and 11 deletions

View File

@ -789,14 +789,15 @@ one will require some configuration to get it working):
|===
| cache name | Description
|`initializr`
|`initializr.metadata`
|Cache the full metadata of the service. When the metadata expires, it is fully resolved
again (including a check on spring.io for the latest Spring Boot versions). Adapt the
expiration settings accordingly.
|`project-resources`
|`initializr.dependency-metadata`
|Cache dependency-specific metadata.
|`initializr.project-resources`
|Cache resources that are used to generate projects.
|`dependency-metadata`
|Cache dependency-specific metadata.
|===

View File

@ -39,7 +39,7 @@ public class ProjectResourceLocator {
* @param location a resource location
* @return the content of the resource
*/
@Cacheable("project-resources")
@Cacheable("initializr.project-resources")
public byte[] getBinaryResource(String location) {
try (InputStream stream = getInputStream(location)) {
return StreamUtils.copyToByteArray(stream);
@ -54,7 +54,7 @@ public class ProjectResourceLocator {
* @param location a resource location
* @return the content of the resource
*/
@Cacheable("project-resources")
@Cacheable("initializr.project-resources")
public String getTextResource(String location) {
try (InputStream stream = getInputStream(location)) {
return StreamUtils.copyToString(stream, UTF_8);

View File

@ -161,10 +161,10 @@ public class InitializrAutoConfiguration {
@Bean
public JCacheManagerCustomizer initializrCacheManagerCustomizer() {
return cm -> {
cm.createCache("initializr", config().setExpiryPolicyFactory(
cm.createCache("initializr.metadata", config().setExpiryPolicyFactory(
CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES)));
cm.createCache("dependency-metadata", config());
cm.createCache("project-resources", config());
cm.createCache("initializr.dependency-metadata", config());
cm.createCache("initializr.project-resources", config());
};
}

View File

@ -37,7 +37,7 @@ import org.springframework.cache.annotation.Cacheable;
public class DefaultDependencyMetadataProvider implements DependencyMetadataProvider {
@Override
@Cacheable(cacheNames = "dependency-metadata", key = "#p1")
@Cacheable(cacheNames = "initializr.dependency-metadata", key = "#p1")
public DependencyMetadata get(InitializrMetadata metadata, Version bootVersion) {
Map<String, Dependency> dependencies = new LinkedHashMap<>();
for (Dependency d : metadata.getDependencies().getAll()) {

View File

@ -49,7 +49,7 @@ public class DefaultInitializrMetadataProvider implements InitializrMetadataProv
}
@Override
@Cacheable(value = "initializr", key = "'metadata'")
@Cacheable(value = "initializr.metadata", key = "'metadata'")
public InitializrMetadata get() {
updateInitializrMetadata(metadata);
return metadata;