-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db): improve performance for db query
1. add cache for db
- Loading branch information
1 parent
2d88f6e
commit 937f445
Showing
19 changed files
with
461 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,4 @@ static boolean isImpl(Snapshot snapshot) { | |
void updateSolidity(); | ||
|
||
String getDbName(); | ||
|
||
boolean isOptimized(); | ||
} |
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
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
44 changes: 44 additions & 0 deletions
44
common/src/main/java/org/tron/common/cache/CacheManager.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,44 @@ | ||
package org.tron.common.cache; | ||
|
||
import com.google.common.cache.CacheLoader; | ||
import com.google.common.cache.CacheStats; | ||
import com.google.common.collect.Maps; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import org.tron.common.parameter.CommonParameter; | ||
|
||
public class CacheManager { | ||
|
||
private static final Map<CacheType, TronCache<?, ?>> CACHES = Maps.newConcurrentMap(); | ||
|
||
public static <K, V> TronCache<K, V> allocate(CacheType name) { | ||
TronCache<K, V> cache = new TronCache<>(name, CommonParameter.getInstance() | ||
.getStorage().getCacheStrategy(name)); | ||
CACHES.put(name, cache); | ||
return cache; | ||
} | ||
|
||
public static <K, V> TronCache<K, V> allocate(CacheType name, String strategy) { | ||
TronCache<K, V> cache = new TronCache<>(name, strategy); | ||
CACHES.put(name, cache); | ||
return cache; | ||
} | ||
|
||
public static <K, V> TronCache<K, V> allocate(CacheType name, String strategy, | ||
CacheLoader<K, V> loader) { | ||
TronCache<K, V> cache = new TronCache<>(name, strategy, loader); | ||
CACHES.put(name, cache); | ||
return cache; | ||
} | ||
|
||
|
||
public static void release(TronCache cache) { | ||
cache.invalidateAll(); | ||
} | ||
|
||
public static Map<String, CacheStats> stats() { | ||
return CACHES.values().stream().collect(Collectors.toMap(c -> c.getName().toString(), | ||
TronCache::stats)); | ||
} | ||
|
||
} |
Oops, something went wrong.