-
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 5a96e5d
Showing
17 changed files
with
382 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
45 changes: 45 additions & 0 deletions
45
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,45 @@ | ||
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<String, TronCache<?, ?>> CACHES = Maps.newConcurrentMap(); | ||
|
||
public static <K, V> TronCache<K, V> allocate(String 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(String 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(String 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(String name) { | ||
TronCache cache = CACHES.remove(name); | ||
if (cache != null) { | ||
cache.invalidateAll(); | ||
} | ||
} | ||
|
||
public static Map<String, CacheStats> stats() { | ||
return CACHES.values().stream().collect(Collectors.toMap(TronCache::getName, TronCache::stats)); | ||
} | ||
|
||
} |
Oops, something went wrong.