Skip to content

Commit

Permalink
优化javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
qiujiayu committed Apr 21, 2015
1 parent c6bf68f commit 35cf9ab
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 45 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<version>2.10.3</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/jarvis/cache/AbstractCacheManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public AutoLoadHandler<T> getAutoLoadHandler() {
* 生成缓存 Key
* @param pjp
* @param cache
* @return
* @return String 缓存Key
*/
private String getCacheKey(ProceedingJoinPoint pjp, Cache cache) {
String className=pjp.getTarget().getClass().getName();
Expand All @@ -60,12 +60,13 @@ private String getCacheKey(ProceedingJoinPoint pjp, Cache cache) {
}
return cacheKey;
}

/**
* 生成缓存 Key
* @param pjp
* @param cache
* @param result 执行结果值
* @return
* @return 缓存Key
*/
private String getCacheKey(ProceedingJoinPoint pjp, Cache cache, T result) {
String className=pjp.getTarget().getClass().getName();
Expand All @@ -84,7 +85,7 @@ private String getCacheKey(ProceedingJoinPoint pjp, Cache cache, T result) {
* 处理@Cache 拦截
* @param pjp
* @param cache
* @return
* @return T 返回值
* @throws Exception
*/
public T proceed(ProceedingJoinPoint pjp, Cache cache) throws Exception {
Expand Down Expand Up @@ -143,9 +144,8 @@ private void writeCache(T result, String cacheKey, int expire) {
* @param pjp
* @param autoLoadTO
* @param cacheKey
* @param cacheManager
* @param expire
* @return
* @return 返回值
* @throws Exception
*/
private T loadData(ProceedingJoinPoint pjp, AutoLoadTO autoLoadTO, String cacheKey, int expire) throws Exception {
Expand Down Expand Up @@ -227,10 +227,9 @@ private T getData(ProceedingJoinPoint pjp, AutoLoadTO autoLoadTO) throws Excepti

/**
* 处理@CacheDelete 拦截
* @param pjp
* @param jp
* @param cacheDelete 拦截到的注解
* @param retVal 返回值
* @throws Exception
*/
public void deleteCache(JoinPoint jp, CacheDelete cacheDelete, Object retVal) {
Object[] arguments=jp.getArgs();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jarvis/cache/AutoLoadHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void setAutoLoadTO(AutoLoadTO autoLoadTO) {

/**
* 获取自动加载队列,如果是web应用,建议把自动加载队列中的数据都输出到页面中,并增加一些管理功能。
* @return
* @return autoload 队列
*/
public AutoLoadTO[] getAutoLoadQueue() {
if(autoLoadMap.isEmpty()) {
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/jarvis/cache/CacheUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CacheUtil {
/**
* 生成字符串的HashCode
* @param buf
* @return
* @return int hashCode
*/
private static int getHashCode(String buf) {
int hash=5381;
Expand All @@ -45,7 +45,7 @@ private static int getHashCode(String buf) {
/**
* 将Object 对象转换为唯一的Hash字符串
* @param obj
* @return
* @return Hash字符串
*/
public static String getUniqueHashStr(Object obj) {
return getMiscHashCode(BeanUtil.toString(obj));
Expand All @@ -54,7 +54,7 @@ public static String getUniqueHashStr(Object obj) {
/**
* 通过混合Hash算法,将长字符串转为短字符串(字符串长度小于等于20时,不做处理)
* @param str
* @return
* @return Hash字符串
*/
public static String getMiscHashCode(String str) {
if(null == str || str.length() == 0) {
Expand All @@ -80,7 +80,7 @@ public static String getMiscHashCode(String str) {
* @param keySpEL
* @param arguments
* @param valueType
* @return
* @return EL Value
*/
public static <T> T getElValue(String keySpEL, Object[] arguments, Class<T> valueType) {
return getElValue(keySpEL, arguments, null, valueType);
Expand All @@ -92,7 +92,7 @@ public static <T> T getElValue(String keySpEL, Object[] arguments, Class<T> valu
* @param arguments
* @param valueType
* @param retVal
* @return
* @return EL value
*/
public static <T> T getElValue(String keySpEL, Object[] arguments, Object retVal, Class<T> valueType) {
Matcher m=pattern_hash.matcher(keySpEL);
Expand All @@ -111,7 +111,7 @@ public static <T> T getElValue(String keySpEL, Object[] arguments, Object retVal
* 生成自定义缓存Key
* @param keySpEL
* @param arguments
* @return
* @return cacheKey
*/
public static String getDefinedCacheKey(String keySpEL, Object[] arguments) {
if(keySpEL.indexOf("#" + ARGS) != -1) {
Expand All @@ -126,7 +126,7 @@ public static String getDefinedCacheKey(String keySpEL, Object[] arguments) {
* @param keySpEL
* @param arguments
* @param retVal
* @return
* @return CacheKey
*/
public static String getDefinedCacheKey(String keySpEL, Object[] arguments, Object retVal) {
if(keySpEL.indexOf("#" + ARGS) != -1 || keySpEL.indexOf("#" + RET_VAL) != -1) {
Expand All @@ -141,7 +141,7 @@ public static String getDefinedCacheKey(String keySpEL, Object[] arguments, Obje
* @param className 类名称
* @param method 方法名称
* @param arguments 参数
* @return
* @return CacheKey
*/
public static String getDefaultCacheKey(String className, String method, Object[] arguments) {
StringBuilder sb=new StringBuilder();
Expand All @@ -158,7 +158,7 @@ public static String getDefaultCacheKey(String className, String method, Object[
* @param method 方法名称
* @param arguments 参数
* @param subKeySpEL SpringEL表达式,arguments 在SpringEL表达式中的名称为args,第一个参数为#args[0],第二个为参数为#args[1],依此类推。
* @return
* @return CacheKey
*/
public static String getDefaultCacheKey(String className, String method, Object[] arguments, String subKeySpEL) {
StringBuilder sb=new StringBuilder();
Expand All @@ -175,7 +175,7 @@ public static String getDefaultCacheKey(String className, String method, Object[
* @param method 方法名称
* @param arguments 参数
* @param subKeySpEL SpringEL表达式 ,arguments 在SpringEL表达式中的名称为args,第一个参数为#args[0],第二个为参数为#args[1],依此类推。
* @return
* @return CacheKey
*/
public static String getDefaultCacheKeyPrefix(String className, String method, Object[] arguments, String subKeySpEL) {
StringBuilder sb=new StringBuilder();
Expand All @@ -194,7 +194,7 @@ public static String getDefaultCacheKeyPrefix(String className, String method, O
* 是否可以缓存
* @param cache
* @param arguments
* @return
* @return cacheAble
*/
public static boolean isCacheable(Cache cache, Object[] arguments) {
boolean rv=true;
Expand All @@ -208,7 +208,7 @@ public static boolean isCacheable(Cache cache, Object[] arguments) {
* 是否可以自动加载
* @param cache
* @param arguments
* @return
* @return autoload
*/
public static boolean isAutoload(Cache cache, Object[] arguments) {
boolean autoload=cache.autoload();
Expand All @@ -223,7 +223,7 @@ public static boolean isAutoload(Cache cache, Object[] arguments) {
* @param cacheDeleteKey
* @param arguments
* @param retVal
* @return
* @return Can Delete
*/
public static boolean isCanDelete(CacheDeleteKey cacheDeleteKey, Object[] arguments, Object retVal) {
boolean rv=true;
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/jarvis/cache/ICacheManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,40 @@
import com.jarvis.cache.to.CacheWrapper;

/**
* 缓存管理
* @author jiayu.qiu
*/
public interface ICacheManager<T> {

/**
* 往缓存写数据
* @param cacheKey 缓存Key
* @param result 缓存数据
* @param expire 缓存时间
*/
void setCache(String cacheKey, CacheWrapper<T> result, int expire);

/**
* 根据缓存Key获得缓存中的数据
* @param key 缓存key
* @return 缓存数据
*/
CacheWrapper<T> get(String key);

/**
* 删除缓存
* @param key 缓存key
*/
void delete(String key);

/**
* 获取自动加载处理器
* @return 自动加载处理器
*/
AutoLoadHandler<T> getAutoLoadHandler();

/**
* 销毁:关闭线程
*/
void destroy();
}
14 changes: 7 additions & 7 deletions src/main/java/com/jarvis/cache/annotation/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,43 @@

/**
* 自定义缓存Key,如果不设置使用系统默认生成缓存Key的方法
* @return
* @return String 自定义缓存Key
*/
String key() default "";

/**
* 是否启用自动加载缓存
* @return
* @return boolean
*/
boolean autoload() default false;

/**
* 自动缓存的条件,可以为空,使用 SpEL 编写,返回 true 或者 false,如果设置了此值,autoload() 就失效,例如:null != #args[0].keyword,当第一个参数的keyword属性为null时设置为自动加载。
* @return
* @return String SpEL表达式
*/
String autoloadCondition() default "";

/**
* 当autoload为true时,缓存数据在 requestTimeout 秒之内没有使用了,就不进行自动加载数据,如果requestTimeout为0时,会一直自动加载
* @return
* @return long 请求过期
*/
long requestTimeout() default 36000L;

/**
* 使用SpEL,将缓存key,根据业务需要进行二次分组(使用默认缓存Key的时候才有效)
* @return
* @return String
*/
String subKeySpEL() default "";

/**
* 缓存的条件,可以为空,使用 SpEL 编写,返回 true 或者 false,只有为 true 才进行缓存
* @return
* @return String
*/
String condition() default "";

/**
* 缓存的操作类型:默认是READ_WRITE,先缓存取数据,如果没有数据则从DAO中获取并写入缓存;如果是WRITE则从DAO取完数据后,写入缓存
* @return
* @return CacheOpType
*/
CacheOpType opType() default CacheOpType.READ_WRITE;
}
16 changes: 8 additions & 8 deletions src/main/java/com/jarvis/cache/annotation/CacheDeleteKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,50 @@

/**
* 缓存的条件,可以为空,使用 SpEL 编写,返回 true 或者 false,只有为 true 才进行缓存
* @return
* @return String
*/
String condition() default "";

/**
* 删除缓存的Key,支持使用SpEL表达式
* @return
* @return String
*/
String value() default "";

/**
* 生成Key的类型
* @return
* @return CacheKeyType
*/
CacheKeyType keyType();

/**
* deleteByPrefixKey 是否根据前缀进行批量删除 只有当 keType为DEFAULT时才有效
* @return
* @return boolean
*/
boolean deleteByPrefixKey() default false;

/**
* 缓存的Class 只有当 keType为DEFAULT时才有效
* @return
* @return Class
*/
@SuppressWarnings("rawtypes")
Class cls() default Class.class;

/**
* 缓存所在的方法名
* @return
* @return String
*/
String method() default "";

/**
* 转换缓存方法的参数,当keyType 为DEFAULT 并且 deleteByPrefixKey=true时才会使用上。
* @return
* @return String[]
*/
String[] argsEl() default "";

/**
* 使用SpEL,将缓存key,根据业务需要进行二次分组(使用默认缓存Key的时候才有效) 只有当 keType为DEFAULT时才有效
* @return
* @return String
*/
String subKeySpEL() default "";

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/jarvis/cache/memcache/CachePointCut.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void delete(String key) {
* @param method
* @param arguments
* @param subKeySpEL
* @param deleteByPrefixKey 是否批量删除
*/
public void deleteByDefaultCacheKey(@SuppressWarnings("rawtypes") Class cs, String method, Object[] arguments, String subKeySpEL) {
String cacheKey=CacheUtil.getDefaultCacheKey(cs.getName(), method, arguments, subKeySpEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
/**
* Simple String to byte[] (and back) serializer. Converts Strings into bytes and vice-versa using the specified charset (by default
* UTF-8).
* <p/>
* <p>
* Useful when the interaction with the Redis happens mainly through Strings.
* <p/>
* </p>
* <p>
* Does not perform any null conversion since empty strings are valid keys/values.
* </p>
*/
public class StringRedisSerializer implements RedisSerializer<String> {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jarvis/cache/to/AutoLoadTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void addUseTotalTime(long useTime) {

/**
* 平均用时
* @return
* @return long 用时
*/
public long getAverageUseTime() {
if(loadCnt == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jarvis/cache/type/CacheOpType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* 缓存操作类型
* @author jarvis
* @author jiayu.qiu
*/
public enum CacheOpType {
/**
Expand Down
Loading

0 comments on commit 35cf9ab

Please sign in to comment.