Merge branch 'master' of git@github.com:foxinmy/weixin4j.git
This commit is contained in:
commit
8c1e1719fa
@ -21,16 +21,16 @@ public class FileCacheStorager<T extends Cacheable> implements CacheStorager<T>
|
||||
private final File tmpdir;
|
||||
private final String SEPARATOR = File.separator;
|
||||
|
||||
public FileCacheStorager(String cachePath) {
|
||||
public FileCacheStorager(String path) {
|
||||
this.tmpdir = new File(String.format("%s%sweixin4j_token_temp",
|
||||
cachePath, SEPARATOR));
|
||||
path, SEPARATOR));
|
||||
this.tmpdir.mkdirs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T lookup(String cacheKey) {
|
||||
public T lookup(String key) {
|
||||
File cacheFile = new File(String.format("%s%s%s",
|
||||
tmpdir.getAbsolutePath(), SEPARATOR, cacheKey));
|
||||
tmpdir.getAbsolutePath(), SEPARATOR, key));
|
||||
try {
|
||||
if (cacheFile.exists()) {
|
||||
T cache = SerializationUtils.deserialize(new FileInputStream(
|
||||
@ -50,22 +50,22 @@ public class FileCacheStorager<T extends Cacheable> implements CacheStorager<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void caching(String cacheKey, T cache) {
|
||||
public void caching(String key, T cache) {
|
||||
try {
|
||||
SerializationUtils.serialize(
|
||||
cache,
|
||||
new FileOutputStream(new File(String.format("%s%s%s",
|
||||
tmpdir.getAbsolutePath(), SEPARATOR, cacheKey))));
|
||||
tmpdir.getAbsolutePath(), SEPARATOR, key))));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T evict(String cacheKey) {
|
||||
public T evict(String key) {
|
||||
T cache = null;
|
||||
File cacheFile = new File(String.format("%s%s%s",
|
||||
tmpdir.getAbsolutePath(), SEPARATOR, cacheKey));
|
||||
tmpdir.getAbsolutePath(), SEPARATOR, key));
|
||||
try {
|
||||
if (cacheFile.exists()) {
|
||||
cache = SerializationUtils.deserialize(new FileInputStream(
|
||||
|
||||
@ -35,32 +35,32 @@ public class MemcacheCacheStorager<T extends Cacheable> implements
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T lookup(String cacheKey) {
|
||||
return (T) mc.get(cacheKey);
|
||||
public T lookup(String key) {
|
||||
return (T) mc.get(key);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void caching(String cacheKey, T cache) {
|
||||
public void caching(String key, T cache) {
|
||||
if (cache.getCreateTime() > 0l) {
|
||||
mc.set(cacheKey,
|
||||
mc.set(key,
|
||||
cache,
|
||||
new Date(cache.getCreateTime() + cache.getExpires() - CUTMS));
|
||||
} else {
|
||||
mc.set(cacheKey, cache);
|
||||
mc.set(key, cache);
|
||||
}
|
||||
Set<String> all = (Set<String>) mc.get(ALLKEY);
|
||||
all.add(cacheKey);
|
||||
all.add(key);
|
||||
mc.set(ALLKEY, all);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T evict(String cacheKey) {
|
||||
T cache = lookup(cacheKey);
|
||||
mc.delete(cacheKey);
|
||||
public T evict(String key) {
|
||||
T cache = lookup(key);
|
||||
mc.delete(key);
|
||||
Set<String> all = (Set<String>) mc.get(ALLKEY);
|
||||
all.remove(cacheKey);
|
||||
all.remove(key);
|
||||
mc.set(ALLKEY, all);
|
||||
return cache;
|
||||
}
|
||||
|
||||
@ -22,8 +22,8 @@ public class MemoryCacheStorager<T extends Cacheable> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public T lookup(String cacheKey) {
|
||||
T cache = this.CONMAP.get(cacheKey);
|
||||
public T lookup(String key) {
|
||||
T cache = this.CONMAP.get(key);
|
||||
if (cache != null) {
|
||||
if ((cache.getCreateTime() + cache.getExpires() - CUTMS) > System
|
||||
.currentTimeMillis()) {
|
||||
@ -34,13 +34,13 @@ public class MemoryCacheStorager<T extends Cacheable> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void caching(String cacheKey, T cache) {
|
||||
this.CONMAP.put(cacheKey, cache);
|
||||
public void caching(String key, T cache) {
|
||||
this.CONMAP.put(key, cache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T evict(String cacheKey) {
|
||||
return this.CONMAP.remove(cacheKey);
|
||||
public T evict(String key) {
|
||||
return this.CONMAP.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -60,11 +60,11 @@ public class RedisCacheStorager<T extends Cacheable> implements
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T lookup(String cacheKey) {
|
||||
public T lookup(String key) {
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
jedis = jedisPool.getResource();
|
||||
byte[] value = jedis.get(cacheKey.getBytes(Consts.UTF_8));
|
||||
byte[] value = jedis.get(key.getBytes(Consts.UTF_8));
|
||||
return value != null ? (T) SerializationUtils.deserialize(value)
|
||||
: null;
|
||||
} finally {
|
||||
@ -75,19 +75,19 @@ public class RedisCacheStorager<T extends Cacheable> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void caching(String cacheKey, T cache) {
|
||||
public void caching(String key, T cache) {
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
jedis = jedisPool.getResource();
|
||||
byte[] key = cacheKey.getBytes(Consts.UTF_8);
|
||||
byte[] cacheKey = key.getBytes(Consts.UTF_8);
|
||||
byte[] value = SerializationUtils.serialize(cache);
|
||||
if (cache.getExpires() > 0) {
|
||||
jedis.setex(key, (int) (cache.getExpires() - CUTMS) / 1000,
|
||||
jedis.setex(cacheKey, (int) (cache.getExpires() - CUTMS) / 1000,
|
||||
value);
|
||||
} else {
|
||||
jedis.set(key, value);
|
||||
jedis.set(cacheKey, value);
|
||||
}
|
||||
jedis.sadd(ALLKEY, cacheKey);
|
||||
jedis.sadd(ALLKEY, key);
|
||||
} finally {
|
||||
if (jedis != null) {
|
||||
jedis.close();
|
||||
@ -96,13 +96,13 @@ public class RedisCacheStorager<T extends Cacheable> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public T evict(String cacheKey) {
|
||||
T cache = lookup(cacheKey);
|
||||
public T evict(String key) {
|
||||
T cache = lookup(key);
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
jedis = jedisPool.getResource();
|
||||
jedis.del(cacheKey);
|
||||
jedis.srem(ALLKEY, cacheKey);
|
||||
jedis.del(key);
|
||||
jedis.srem(ALLKEY, key);
|
||||
} finally {
|
||||
if (jedis != null) {
|
||||
jedis.close();
|
||||
|
||||
@ -59,29 +59,29 @@ public class RedisClusterCacheStorager<T extends Cacheable> implements
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T lookup(String cacheKey) {
|
||||
byte[] value = jedisCluster.get(cacheKey.getBytes(Consts.UTF_8));
|
||||
public T lookup(String key) {
|
||||
byte[] value = jedisCluster.get(key.getBytes(Consts.UTF_8));
|
||||
return value != null ? (T) SerializationUtils.deserialize(value) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void caching(String cacheKey, T cache) {
|
||||
byte[] key = cacheKey.getBytes(Consts.UTF_8);
|
||||
public void caching(String key, T cache) {
|
||||
byte[] cacheKey = key.getBytes(Consts.UTF_8);
|
||||
byte[] value = SerializationUtils.serialize(cache);
|
||||
if (cache.getExpires() > 0) {
|
||||
jedisCluster.setex(key, (int) (cache.getExpires() - CUTMS) / 1000,
|
||||
value);
|
||||
jedisCluster.setex(cacheKey,
|
||||
(int) (cache.getExpires() - CUTMS) / 1000, value);
|
||||
} else {
|
||||
jedisCluster.set(key, value);
|
||||
jedisCluster.set(cacheKey, value);
|
||||
}
|
||||
jedisCluster.sadd(ALLKEY, cacheKey);
|
||||
jedisCluster.sadd(ALLKEY, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T evict(String cacheKey) {
|
||||
T cache = lookup(cacheKey);
|
||||
jedisCluster.del(cacheKey);
|
||||
jedisCluster.srem(ALLKEY, cacheKey);
|
||||
public T evict(String key) {
|
||||
T cache = lookup(key);
|
||||
jedisCluster.del(key);
|
||||
jedisCluster.srem(ALLKEY, key);
|
||||
return cache;
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import com.foxinmy.weixin4j.cache.CacheStorager;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
|
||||
/**
|
||||
* 第三方应用组件永久授权码的存取
|
||||
* 第三方应用永久授权码的存取
|
||||
*
|
||||
* @className PerTicketManager
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
|
||||
@ -125,7 +125,7 @@ public class WeixinComponentProxy {
|
||||
* 组件ticket内容
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public void cacheTicket(String componentId, String componentTicket) throws WeixinException {
|
||||
public void cacheComponentTicket(String componentId, String componentTicket) throws WeixinException {
|
||||
component(componentId).getTicketManager().cachingTicket(componentTicket);
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ public class WeixinComponentProxy {
|
||||
* @see {@link #getComponentAuthorizeURL(String, String,String)}
|
||||
* @param componentId
|
||||
* 组件ID
|
||||
* @see {@link #cacheTicket(String, String)}
|
||||
* @see {@link #cacheComponentTicket(String, String)}
|
||||
* @return 请求授权的URL
|
||||
* @throws WeixinException
|
||||
*/
|
||||
|
||||
@ -146,7 +146,7 @@ public class WeixinSuiteProxy {
|
||||
* 推送suite_ticket协议</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public void cacheTicket(String suiteId, String suiteTicket) throws WeixinException {
|
||||
public void cacheSuiteTicket(String suiteId, String suiteTicket) throws WeixinException {
|
||||
suite(suiteId).getTicketManager().cachingTicket(suiteTicket);
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ public class WeixinSuiteProxy {
|
||||
* @see {@link #getSuiteAuthorizeURL(String, String,String)}
|
||||
* @param suiteId
|
||||
* 套件ID
|
||||
* @see {@link #cacheTicket(String, String)}
|
||||
* @see {@link #cacheSuiteTicket(String, String)}
|
||||
* @return 请求授权的URL
|
||||
* @throws WeixinException
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user