-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Change quarkus-cache config phase from BUILD_TIME to RUN_TIME
- Loading branch information
Showing
8 changed files
with
108 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/CacheManagerInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package io.quarkus.cache.runtime; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.context.Initialized; | ||
import javax.enterprise.event.Observes; | ||
|
||
import io.quarkus.cache.CacheManager; | ||
import io.quarkus.runtime.StartupEvent; | ||
|
||
/** | ||
* This class is used to eagerly create the {@link CacheManager} bean instance at STATIC_INIT execution time. | ||
* This class is used to eagerly create the {@link CacheManager} bean instance at RUNTIME_INIT execution time. | ||
*/ | ||
public class CacheManagerInitializer { | ||
|
||
private static void onStaticInit(@Observes @Initialized(ApplicationScoped.class) Object event, CacheManager cacheManager) { | ||
private static void onStartup(@Observes StartupEvent event, CacheManager cacheManager) { | ||
cacheManager.getCacheNames(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/CacheManagerRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.quarkus.cache.runtime; | ||
|
||
import static io.quarkus.cache.runtime.CacheConfig.CAFFEINE_CACHE_TYPE; | ||
|
||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
import javax.enterprise.inject.spi.DeploymentException; | ||
|
||
import io.quarkus.cache.CacheManager; | ||
import io.quarkus.cache.runtime.caffeine.CaffeineCacheManagerBuilder; | ||
import io.quarkus.cache.runtime.noop.NoOpCacheManagerBuilder; | ||
import io.quarkus.runtime.annotations.Recorder; | ||
|
||
@Recorder | ||
public class CacheManagerRecorder { | ||
|
||
private final CacheConfig cacheConfig; | ||
|
||
public CacheManagerRecorder(CacheConfig cacheConfig) { | ||
this.cacheConfig = cacheConfig; | ||
} | ||
|
||
public Supplier<CacheManager> getCacheManagerSupplierWithMicrometerMetrics(Set<String> cacheNames) { | ||
Supplier<Supplier<CacheManager>> caffeineCacheManagerSupplier = new Supplier<Supplier<CacheManager>>() { | ||
@Override | ||
public Supplier<CacheManager> get() { | ||
return CaffeineCacheManagerBuilder.buildWithMicrometerMetrics(cacheNames, cacheConfig); | ||
} | ||
}; | ||
return getCacheManagerSupplier(cacheNames, caffeineCacheManagerSupplier); | ||
} | ||
|
||
public Supplier<CacheManager> getCacheManagerSupplierWithoutMetrics(Set<String> cacheNames) { | ||
Supplier<Supplier<CacheManager>> caffeineCacheManagerSupplier = new Supplier<Supplier<CacheManager>>() { | ||
@Override | ||
public Supplier<CacheManager> get() { | ||
return CaffeineCacheManagerBuilder.buildWithoutMetrics(cacheNames, cacheConfig); | ||
} | ||
}; | ||
return getCacheManagerSupplier(cacheNames, caffeineCacheManagerSupplier); | ||
} | ||
|
||
private Supplier<CacheManager> getCacheManagerSupplier(Set<String> cacheNames, | ||
Supplier<Supplier<CacheManager>> caffeineCacheManagerSupplier) { | ||
if (cacheConfig.enabled) { | ||
switch (cacheConfig.type) { | ||
case CAFFEINE_CACHE_TYPE: | ||
return caffeineCacheManagerSupplier.get(); | ||
default: | ||
throw new DeploymentException("Unknown cache type: " + cacheConfig.type); | ||
} | ||
} else { | ||
return NoOpCacheManagerBuilder.build(cacheNames); | ||
} | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
.../deployment/CaffeineCacheInfoBuilder.java → ...me/caffeine/CaffeineCacheInfoBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters