Conflicts:
	weixin4j-base/src/main/java/com/foxinmy/weixin4j/token/TokenHolder.java
This commit is contained in:
jinyu 2016-03-07 14:10:53 +08:00
commit 333ca283b3
5 changed files with 19 additions and 8 deletions

View File

@ -41,10 +41,10 @@ public interface CacheStorager<T> {
* 缓存key
* @return 移除的对象
*/
T evict(String cacheKey);
T evict(String cacheKey) throws WeixinException;
/**
* 清除所有缓存对象(<font color="red">请慎重</font>)
*/
void clear();
void clear() throws WeixinException;
}

View File

@ -62,7 +62,7 @@ public class FileTokenStorager implements TokenStorager {
}
@Override
public Token evict(String cacheKey) {
public Token evict(String cacheKey) throws WeixinException {
Token token = null;
File token_file = new File(String.format("%s/%s.xml", cachePath,
cacheKey));
@ -79,7 +79,7 @@ public class FileTokenStorager implements TokenStorager {
}
@Override
public void clear() {
public void clear() throws WeixinException {
File[] files = new File(cachePath).listFiles(new FileFilter() {
@Override
public boolean accept(File file) {

View File

@ -41,12 +41,12 @@ public class MemoryTokenStorager implements TokenStorager {
}
@Override
public Token evict(String cacheKey) {
public Token evict(String cacheKey) throws WeixinException {
return this.CONMAP.remove(cacheKey);
}
@Override
public void clear() {
public void clear() throws WeixinException {
this.CONMAP.clear();
}
}

View File

@ -103,7 +103,7 @@ public class RedisTokenStorager implements TokenStorager {
}
@Override
public Token evict(String cacheKey) {
public Token evict(String cacheKey) throws WeixinException {
Token token = null;
try {
token = lookup(cacheKey);
@ -123,7 +123,7 @@ public class RedisTokenStorager implements TokenStorager {
}
@Override
public void clear() {
public void clear() throws WeixinException {
// en....
}
}

View File

@ -74,4 +74,15 @@ public class TokenHolder {
tokenStorager.caching(cacheKey, token);
return token;
}
/**
* 手动移除token
*
* @return 被移除的token
* @throws WeixinException
*/
public Token evictToken() throws WeixinException {
String cacheKey = tokenCreator.getCacheKey();
return tokenStorager.evict(cacheKey);
}
}