Skip to content

Commit

Permalink
Merge pull request #102 from sswguo/slim_image
Browse files Browse the repository at this point in the history
Replace infinispan with the lightweight caffeine
  • Loading branch information
sswguo authored Dec 9, 2024
2 parents 9221c85 + 6c6d9e2 commit 708a413
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 36 deletions.
26 changes: 11 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-mutiny</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx</artifactId>
Expand All @@ -132,25 +131,28 @@
<artifactId>indy-model-core-java</artifactId>
<version>${indyModelVersion}</version>
</dependency>

<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
<version>${keycloakVersion}</version>
</dependency>

<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-adapter-core</artifactId>
<version>${keycloakVersion}</version>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer-registry-prometheus</artifactId>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-exporter-otlp</artifactId>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-semconv</artifactId>
</dependency>

<dependency>
Expand All @@ -174,14 +176,8 @@
</dependency>

<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core-jakarta</artifactId>
<version>${infinispanVersion}</version>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-commons-jakarta</artifactId>
<version>${infinispanVersion}</version>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,39 @@
*/
package org.commonjava.indy.service.httprox.util;

import org.infinispan.Cache;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

@ApplicationScoped
public class CacheProducer
{

private EmbeddedCacheManager cacheManager;

private Map<String, Cache> caches = new ConcurrentHashMap<>();

@PostConstruct
public void start()
{
startEmbeddedManager();
}

private void startEmbeddedManager()
{
cacheManager = new DefaultCacheManager();
}

public synchronized <K, V> Cache<K, V> getCache( String named )
{
return caches.computeIfAbsent( named, ( k ) -> buildCache(named));
return caches.computeIfAbsent( named, ( k ) -> buildCache());
}

private Cache buildCache(String named)
private Cache buildCache()
{
cacheManager.defineConfiguration( named, new ConfigurationBuilder().build() );
return cacheManager.getCache(named, Boolean.TRUE);
Cache<String, String> cache = Caffeine.newBuilder()
.maximumSize( 50 )
.expireAfterAccess(15, TimeUnit.MINUTES)
.build();
return cache;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.commonjava.indy.service.httprox.handler.ProxyCreationResult;
import org.commonjava.indy.service.httprox.handler.ProxyRepositoryCreator;
import org.commonjava.indy.service.httprox.model.TrackingKey;
import org.infinispan.Cache;
import com.github.benmanes.caffeine.cache.Cache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -151,9 +151,9 @@ private ArtifactStore doGetArtifactStore(String trackingId, final URL url )

if ( trackingId != null )
{
if ( cache.get( groupName ) != null )
if ( cache.getIfPresent( groupName ) != null )
{
return (ArtifactStore) cache.get( groupName );
return (ArtifactStore) cache.getIfPresent( groupName );
}

Group group = null;
Expand All @@ -165,7 +165,7 @@ private ArtifactStore doGetArtifactStore(String trackingId, final URL url )
if ( response != null && response.getStatus() == HttpStatus.SC_OK )
{
group = (Group)response.readEntity(ArtifactStore.class);
cache.put(groupName, group, 15, TimeUnit.MINUTES);
cache.put(groupName, group);
}
}
catch ( WebApplicationException e )
Expand All @@ -176,7 +176,7 @@ private ArtifactStore doGetArtifactStore(String trackingId, final URL url )
url, trackingId );
ProxyCreationResult result = createRepo( trackingId, url, null );
group = result.getGroup();
cache.put(groupName, group, 15, TimeUnit.MINUTES);
cache.put(groupName, group);
return group;
}
else
Expand Down

0 comments on commit 708a413

Please sign in to comment.