Skip to content

Commit

Permalink
[ISSUE alibaba#7487] Add generics for the CacheBuilder. (alibaba#7490)
Browse files Browse the repository at this point in the history
  • Loading branch information
onewe authored Apr 27, 2022
1 parent 92a0eb0 commit 8980a96
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Limiter {
private static final Cache<String, RateLimiter> CACHE;

static {
CACHE = CacheBuilder.builder()
CACHE = CacheBuilder.<String, RateLimiter>builder()
.expireNanos(1, TimeUnit.MINUTES)
.initializeCapacity(CAPACITY_SIZE)
.sync(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class CacheBuilder<K, V> {
private static final int DEFAULT_EXPIRE_NANOS = -1;

private long expireNanos = DEFAULT_EXPIRE_NANOS;

private int maximumSize = DEFAULT_MAXIMUMSIZE;

private int initializeCapacity = DEFAULT_INITIALIZE_CAPACITY;
Expand All @@ -48,14 +48,14 @@ public class CacheBuilder<K, V> {

private boolean lru = false;

public static CacheBuilder builder() {
return new CacheBuilder();
public static <K, V> CacheBuilder<K, V> builder() {
return new CacheBuilder<>();
}

/**
* Set expiration time.
*/
public CacheBuilder expireNanos(long duration, TimeUnit unit) {
public CacheBuilder<K, V> expireNanos(long duration, TimeUnit unit) {
checkExpireNanos(duration, unit);
this.expireNanos = unit.toNanos(duration);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class StringPool {
private static final Cache<String, String> GROUP_KEY_CACHE;

static {
GROUP_KEY_CACHE = CacheBuilder.builder().maximumSize(5000000)
GROUP_KEY_CACHE = CacheBuilder.<String, String>builder().maximumSize(5000000)
.expireNanos(180, TimeUnit.SECONDS)
.lru(true)
.build();
Expand Down

0 comments on commit 8980a96

Please sign in to comment.