-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CacheNameGenerator, now you can custom your own CacheNameGenerato…
…r by overwriting SpringConfigProvider: @bean public SpringConfigProvider springConfigProvider() { return new SpringConfigProvider(){ public CacheNameGenerator createCacheNameGenerator(String[] hiddenPackages){ return MyCacheNameGenerator(); } }; }
- Loading branch information
Showing
5 changed files
with
63 additions
and
8 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
17 changes: 17 additions & 0 deletions
17
jetcache-anno/src/main/java/com/alicp/jetcache/anno/support/CacheNameGenerator.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,17 @@ | ||
/** | ||
* Created on 2018/3/22. | ||
*/ | ||
package com.alicp.jetcache.anno.support; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* @author <a href="mailto:areyouok@gmail.com">huangli</a> | ||
*/ | ||
public interface CacheNameGenerator { | ||
|
||
String generateCacheName(Method method); | ||
|
||
String generateCacheName(Field field); | ||
} |
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
37 changes: 37 additions & 0 deletions
37
jetcache-anno/src/main/java/com/alicp/jetcache/anno/support/DefaultCacheNameGenerator.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,37 @@ | ||
/** | ||
* Created on 2018/3/22. | ||
*/ | ||
package com.alicp.jetcache.anno.support; | ||
|
||
import com.alicp.jetcache.anno.method.ClassUtil; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* @author <a href="mailto:areyouok@gmail.com">huangli</a> | ||
*/ | ||
public class DefaultCacheNameGenerator implements CacheNameGenerator { | ||
|
||
private String[] hiddenPackages; | ||
|
||
public DefaultCacheNameGenerator(String[] hiddenPackages) { | ||
this.hiddenPackages = hiddenPackages; | ||
} | ||
|
||
@Override | ||
public String generateCacheName(Method method) { | ||
return ClassUtil.generateCacheName(method, hiddenPackages); | ||
} | ||
|
||
@Override | ||
public String generateCacheName(Field field) { | ||
StringBuilder sb = new StringBuilder(); | ||
String className = field.getDeclaringClass().getName(); | ||
className = ClassUtil.removeHiddenPackage(hiddenPackages, className); | ||
className = ClassUtil.getShortClassName(className); | ||
sb.append(className); | ||
sb.append(".").append(field.getName()); | ||
return sb.toString(); | ||
} | ||
} |