-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
112 additions
and
42 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
29 changes: 29 additions & 0 deletions
29
jswitcher-ui/src/main/java/com/github/xincao9/jswitcher/ui/config/RootConfig.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,29 @@ | ||
package com.github.xincao9.jswitcher.ui.config; | ||
|
||
import com.github.benmanes.caffeine.cache.Cache; | ||
import com.github.benmanes.caffeine.cache.Caffeine; | ||
import com.github.xincao9.jswitcher.ui.core.CustomCacheManager; | ||
import java.util.concurrent.TimeUnit; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* | ||
* @author [email protected] | ||
*/ | ||
@Configuration | ||
public class RootConfig { | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
@Bean | ||
public CustomCacheManager customCacheManager() { | ||
CustomCacheManager customCacheManager = new CustomCacheManager(); | ||
Cache defaultCache = Caffeine.newBuilder().recordStats().expireAfterWrite(5, TimeUnit.SECONDS).maximumSize(5000).build(); | ||
customCacheManager.setDefaultCache(defaultCache); | ||
return customCacheManager; | ||
} | ||
|
||
} |
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
40 changes: 40 additions & 0 deletions
40
jswitcher-ui/src/main/java/com/github/xincao9/jswitcher/ui/core/CustomCacheManager.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,40 @@ | ||
package com.github.xincao9.jswitcher.ui.core; | ||
|
||
import com.github.benmanes.caffeine.cache.Cache; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* | ||
* @author [email protected] | ||
*/ | ||
public class CustomCacheManager { | ||
|
||
private final Map<String, Cache> caches = new ConcurrentHashMap(); | ||
private Cache defaultCache; | ||
|
||
public <K, V> Cache<K, V> getCache(String name) { | ||
if (caches.containsKey(name)) { | ||
return caches.get(name); | ||
} | ||
if (defaultCache != null) { | ||
return defaultCache; | ||
} | ||
return null; | ||
} | ||
|
||
public void register(String name, Cache cache) { | ||
if (!caches.containsKey(name) && cache != null && caches.size() <= 100) { | ||
caches.put(name, cache); | ||
} | ||
} | ||
|
||
public void setDefaultCache(Cache cache) { | ||
this.defaultCache = cache; | ||
} | ||
|
||
public Cache getDefaultCache() { | ||
return this.defaultCache; | ||
} | ||
|
||
} |
File renamed without changes.