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 | cache name | Description
|`initializr` |`initializr.metadata`
|Cache the full metadata of the service. When the metadata expires, it is fully resolved |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 again (including a check on spring.io for the latest Spring Boot versions). Adapt the
expiration settings accordingly. expiration settings accordingly.
|`project-resources` |`initializr.dependency-metadata`
|Cache dependency-specific metadata.
|`initializr.project-resources`
|Cache resources that are used to generate projects. |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 * @param location a resource location
* @return the content of the resource * @return the content of the resource
*/ */
@Cacheable("project-resources") @Cacheable("initializr.project-resources")
public byte[] getBinaryResource(String location) { public byte[] getBinaryResource(String location) {
try (InputStream stream = getInputStream(location)) { try (InputStream stream = getInputStream(location)) {
return StreamUtils.copyToByteArray(stream); return StreamUtils.copyToByteArray(stream);
@@ -54,7 +54,7 @@ public class ProjectResourceLocator {
* @param location a resource location * @param location a resource location
* @return the content of the resource * @return the content of the resource
*/ */
@Cacheable("project-resources") @Cacheable("initializr.project-resources")
public String getTextResource(String location) { public String getTextResource(String location) {
try (InputStream stream = getInputStream(location)) { try (InputStream stream = getInputStream(location)) {
return StreamUtils.copyToString(stream, UTF_8); return StreamUtils.copyToString(stream, UTF_8);

View File

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

View File

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

View File

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