本文整理汇总了Java中org.apache.shiro.cache.CacheException类的典型用法代码示例。如果您正苦于以下问题:Java CacheException类的具体用法?Java CacheException怎么用?Java CacheException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CacheException类属于org.apache.shiro.cache包,在下文中一共展示了CacheException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clear
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
@Override
public void clear() throws CacheException {
Jedis jedis = null;
try
{
jedis = redisManager.getJedis();
jedis.select(DB_INDEX);
jedis.flushDB();
}finally
{
if(null != jedis)
{
jedis.close();
}
}
}
示例2: get
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public V get(K key) throws CacheException {
if (key == null) {
return null;
}
V v = null;
HttpServletRequest request = Servlets.getRequest();
if (request != null) {
v = (V) request.getAttribute(cacheKeyName);
if (v != null) {
return v;
}
}
V value = null;
value = (V) getSession().getAttribute(cacheKeyName);
logger.debug("get {} {} {}", cacheKeyName, key, request != null ? request.getRequestURI() : "");
if (request != null && value != null) {
request.setAttribute(cacheKeyName, value);
}
return value;
}
示例3: put
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
@Override
public V put(K key, V value) throws CacheException {
if (key == null) {
return null;
}
Jedis jedis = null;
try {
jedis = JedisUtils.getResource();
jedis.hset(JedisUtils.getBytesKey(cacheKeyName), JedisUtils.getBytesKey(key), JedisUtils.toBytes(value));
logger.debug("put {} {} = {}", cacheKeyName, key, value);
} catch (Exception e) {
logger.error("put {} {}", cacheKeyName, key, e);
} finally {
JedisUtils.returnResource(jedis);
}
return value;
}
示例4: remove
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public V remove(K key) throws CacheException {
V value = null;
Jedis jedis = null;
try {
jedis = JedisUtils.getResource();
value = (V) JedisUtils.toObject(jedis.hget(JedisUtils.getBytesKey(cacheKeyName), JedisUtils.getBytesKey(key)));
jedis.hdel(JedisUtils.getBytesKey(cacheKeyName), JedisUtils.getBytesKey(key));
logger.debug("remove {} {}", cacheKeyName, key);
} catch (Exception e) {
logger.warn("remove {} {}", cacheKeyName, key, e);
} finally {
JedisUtils.returnResource(jedis);
}
return value;
}
示例5: put
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
public Object put(final String key, final Object value) throws CacheException {
final String realKey = key(key);
return redisTemplate.execute(new SessionCallback<Object>(){
public Object execute(RedisOperations operations) throws DataAccessException {
operations.multi();//事务开启
operations.opsForValue().get(realKey);
if(cacheExpire){
operations.opsForValue().set(realKey, value, cacheExpireSeconds, TimeUnit.SECONDS);
}else{
operations.opsForValue().set(realKey, value);
}
List<Object> results = operations.exec(); //结束事务
return results.get(0);
}
});
}
示例6: getCache
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
@Override
public <K, V> Cache<K, V> getCache(String name) throws CacheException {
logger.debug("获取名称为: " + name + " 的RedisCache实例");
Cache c = caches.get(name);
if (c == null) {
// create a new cache instance
c = new RedisCache<K, V>(jedisClient, keyPrefix);
// add it to the cache collection
caches.put(name, c);
}
return c;
}
示例7: get
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
@Override
public V get(K key) throws CacheException {
logger.debug("根据key从Redis中获取对象 key [" + key + "]");
try {
if (key == null) {
return null;
}else{
byte[] rawValue = cache.get(getByteKey(key));
V value = (V)JavaSerializeUtil.deserialize(rawValue);
return value;
}
} catch (Throwable t) {
throw new CacheException(t);
}
}
示例8: get
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public V get(K key) throws CacheException {
if (key == null){
return null;
}
V v = null;
HttpServletRequest request = Servlets.getRequest();
if (request != null){
v = (V)request.getAttribute(cacheKeyName);
if (v != null){
return v;
}
}
V value = null;
value = (V)getSession().getAttribute(cacheKeyName);
logger.debug("get {} {} {}", cacheKeyName, key, request != null ? request.getRequestURI() : "");
if (request != null && value != null){
request.setAttribute(cacheKeyName, value);
}
return value;
}
示例9: put
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
@Override
public V put(K key, V value) throws CacheException {
if (key == null){
return null;
}
Jedis jedis = null;
try {
jedis = JedisUtils.getResource();
jedis.hset(JedisUtils.getBytesKey(cacheKeyName), JedisUtils.getBytesKey(key), JedisUtils.toBytes(value));
logger.debug("put {} {} = {}", cacheKeyName, key, value);
} catch (Exception e) {
logger.error("put {} {}", cacheKeyName, key, e);
} finally {
JedisUtils.returnResource(jedis);
}
return value;
}
示例10: remove
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public V remove(K key) throws CacheException {
V value = null;
Jedis jedis = null;
try {
jedis = JedisUtils.getResource();
value = (V)JedisUtils.toObject(jedis.hget(JedisUtils.getBytesKey(cacheKeyName), JedisUtils.getBytesKey(key)));
jedis.hdel(JedisUtils.getBytesKey(cacheKeyName), JedisUtils.getBytesKey(key));
logger.debug("remove {} {}", cacheKeyName, key);
} catch (Exception e) {
logger.warn("remove {} {}", cacheKeyName, key, e);
} finally {
JedisUtils.returnResource(jedis);
}
return value;
}
示例11: put
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
public V put(K k, V v) throws CacheException {
trace("Putting object", k);
V previousValue = null;
while (true) {
previousValue = cache.get(k);
if (previousValue == null) {
if (cache.putIfAbsent(k, v) == null) {
break;
}
} else {
if (cache.replace(k, v) != null) {
break;
}
}
}
return previousValue;
}
示例12: remove
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
public V remove(K k) throws CacheException {
trace("Removing object", k);
V previousValue = null;
while (true) {
previousValue = cache.get(k);
if (previousValue == null) {
break;
} else {
if (cache.remove(k, previousValue)) {
break;
}
}
}
return previousValue;
}
示例13: getCache
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public <K, V> Cache<K, V> getCache(String name) throws CacheException {
log.trace("Acquiring EhcacheShiro instance named [{}]", name);
try {
org.ehcache.Cache<Object, Object> cache = ensureCacheManager().getCache(name, Object.class, Object.class);
if (cache == null) {
log.info("Cache with name {} does not yet exist. Creating now.", name);
cache = createCache(name);
log.info("Added EhcacheShiro named [{}]", name);
} else {
log.info("Using existing EhcacheShiro named [{}]", name);
}
return new EhcacheShiro<K, V>(cache);
} catch (MalformedURLException e) {
throw new CacheException(e);
}
}
示例14: get
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
@Override
public V get(K key) throws CacheException {
logger.debug("根据key从Redis中获取对象 key [" + key + "]");
try {
if (key == null) {
return null;
} else {
byte[] rawValue = redisDao.getByte(key.toString());
@SuppressWarnings("unchecked")
V value = (V) SerializationUtils.deserialize(rawValue);
return value;
}
} catch (Throwable t) {
throw new CacheException(t);
}
}
示例15: clear
import org.apache.shiro.cache.CacheException; //导入依赖的package包/类
@Override
public void clear() throws CacheException {
logger.debug("clear redis all data!");
try {
synchronized (this) {
Set<byte[]> keys = cache.keys(this.keyPrefix + "*");
if (!CollectionUtils.isEmpty(keys)) {
for (byte[] key : keys) {
cache.del(key);
}
}
}
} catch (Throwable t) {
throw new CacheException(t);
}
}