List of usage examples for org.apache.shiro.cache CacheException CacheException
public CacheException(Throwable cause)
CacheException. From source file:cn.com.xl.core.shiro.redis.RedisCache.java
License:Apache License
@Override public V get(K key) throws CacheException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("?? [" + getName() + "] [" + key + "] ?"); }//www . j av a 2 s . c om IJedis jedis = initJedis(); try { if (key == null) { return null; } else { V value = jedis.hget(getName(), key); if (value == null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(": [" + key + "] "); } return null; } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug(": [" + key + "] ,"); } return value; } } } catch (Throwable t) { throw new CacheException(t); } }
From source file:cn.com.xl.core.shiro.redis.RedisCache.java
License:Apache License
@Override public V put(K key, V value) throws CacheException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("??? [" + getName() + "] [" + key + "] "); }/* w w w . j ava2 s . com*/ IJedis jedis = initJedis(); try { V previous = get(key); jedis.hset(getName(), key, value); return previous; } catch (Throwable t) { throw new CacheException(t); } }
From source file:cn.com.xl.core.shiro.redis.RedisCache.java
License:Apache License
@Override public V remove(K key) throws CacheException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("?? [" + getName() + "] [" + key + "] "); }/* ww w . ja va 2 s .c o m*/ IJedis jedis = initJedis(); try { V previous = get(key); long statusCode = jedis.hdel(getName(), key); if (statusCode > 0) { if (LOGGER.isInfoEnabled()) { LOGGER.info("??[{}] [{}] ?", getName(), key); } } return previous; } catch (Throwable t) { throw new CacheException(t); } }
From source file:cn.com.xl.core.shiro.redis.RedisCache.java
License:Apache License
@Override public void clear() throws CacheException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("?? [" + getName() + "] "); }/*from w ww . j av a2s. com*/ IJedis jedis = initJedis(); try { String statusCode = jedis.flushDB(); if ("OK".equalsIgnoreCase(statusCode)) { if (LOGGER.isInfoEnabled()) { LOGGER.info(" DB_{} ?.", jedis.getDB()); } } } catch (Throwable t) { throw new CacheException(t); } }
From source file:cn.com.xl.core.shiro.redis.RedisCache.java
License:Apache License
@Override public int size() { IJedis jedis = initJedis();/*from ww w. j a v a 2 s . c om*/ try { long size = jedis.dbSize(); return Long.valueOf(size).intValue(); } catch (Throwable t) { throw new CacheException(t); } }
From source file:cn.com.xl.core.shiro.redis.RedisCache.java
License:Apache License
@Override @SuppressWarnings("unchecked") public Set<K> keys() { IJedis jedis = initJedis();//from w w w .j a va 2 s . c om try { Set<Object> keySet = jedis.hkeys(getName()); if (!CollectionUtils.isEmpty(keySet)) { Set<K> keys = new LinkedHashSet<K>(); for (Object key : keySet) { keys.add((K) key); } return keys; } else { return Collections.emptySet(); } } catch (Throwable t) { throw new CacheException(t); } }
From source file:cn.com.xl.core.shiro.redis.RedisCache.java
License:Apache License
@Override public Collection<V> values() { try {//from www .ja v a2 s . c o m Set<K> keys = keys(); if (!CollectionUtils.isEmpty(keys)) { List<V> values = new ArrayList<V>(keys.size()); for (K key : keys) { V value = get(key); if (value != null) { values.add(value); } } return Collections.unmodifiableList(values); } else { return Collections.emptyList(); } } catch (Throwable t) { throw new CacheException(t); } }
From source file:com.github.zbiljic.shiro.cache.infinispan.InfinispanCache.java
License:Open Source License
/** * Gets a value of an element which matches the given key. * * @param key the key of the element to return. * @return The value placed into the cache with an earlier put, or null if not found or expired *//*from w ww. j av a 2 s .c om*/ @Override public V get(K key) throws CacheException { try { if (log.isTraceEnabled()) { log.trace("Getting object from cache [" + cache.getName() + "] for key [" + key + "]"); } if (key == null) { return null; } Object value = cache.get(key); if (value == null) { if (log.isTraceEnabled()) { log.trace("Object for [" + key + "] is null."); } return null; } else { //noinspection unchecked return (V) value; } } catch (Throwable t) { throw new CacheException(t); } }
From source file:com.github.zbiljic.shiro.cache.infinispan.InfinispanCache.java
License:Open Source License
/** * Puts an object into the cache./*ww w.jav a2 s . com*/ * * @param key the key. * @param value the value. */ @Override public V put(K key, V value) throws CacheException { if (log.isTraceEnabled()) { log.trace("Putting object in cache [" + cache.getName() + "] for key [" + key + "]"); } try { V previous = get(key); cache.put(key, value); return previous; } catch (Throwable t) { throw new CacheException(t); } }
From source file:com.github.zbiljic.shiro.cache.infinispan.InfinispanCache.java
License:Open Source License
/** * Removes the value which matches the key. * * If no key matches, nothing is removed and no Exception is thrown. * * @param key the key of the element to remove *///from w ww . j a v a 2 s . com @Override public V remove(K key) throws CacheException { if (log.isTraceEnabled()) { log.trace("Removing object from cache [" + cache.getName() + "] for key [" + key + "]"); } try { V previous = get(key); cache.remove(key); return previous; } catch (Throwable t) { throw new CacheException(t); } }