Java Code Examples for net.sf.ehcache.Cache#remove()
The following examples show how to use
net.sf.ehcache.Cache#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ECacheProvider.java From anyline with Apache License 2.0 | 5 votes |
public boolean remove(String channel, String key){ boolean result = true; try{ Cache cache = getCache(channel); if(null != cache){ cache.remove(key); } if(ConfigTable.isDebug() && log.isWarnEnabled()){ log.warn("[删除缓存数据] [channel:{}][key:{}]",channel, key); } }catch(Exception e){ result = false; } return result; }
Example 2
Source File: EhCacheUtil.java From zheng with MIT License | 5 votes |
/** * 删除缓存记录 * @param cacheName * @param key * @return */ public static boolean remove(String cacheName, String key) { Cache cache = getCache(cacheName); if (null == cache) { return false; } return cache.remove(key); }
Example 3
Source File: RemoveCacheKeyPipe.java From iaf with Apache License 2.0 | 5 votes |
@Override public PipeRunResult doPipe(Message message, IPipeLineSession session) throws PipeRunException { try { String cacheKey = keyTransformer.transformKey(message.asString(), session); Cache cache = ibisCacheManager.getCache(cacheName); if (cache.remove("r"+cacheKey) && cache.remove("s"+cacheKey)) { log.debug("removed cache key [" + cacheKey + "] from cache ["+cacheName+"]"); } else { log.warn("could not find cache key [" + cacheKey + "] to remove from cache ["+cacheName+"]"); } return new PipeRunResult(getForward(), message); } catch (IOException e) { throw new PipeRunException(this, "cannot open stream", e); } }
Example 4
Source File: EhcacheMonitorController.java From es with Apache License 2.0 | 5 votes |
@RequestMapping("{cacheName}/{key}/delete") @ResponseBody public Object delete( @PathVariable("cacheName") String cacheName, @PathVariable("key") String key ) { Cache cache = cacheManager.getCache(cacheName); cache.remove(key); return "操作成功!"; }
Example 5
Source File: DomainAccessControlStoreEhCache.java From joynr with Apache License 2.0 | 5 votes |
private boolean removeAce(CacheId cacheId, Object aceKey) { Cache cache = getCache(cacheId); boolean removeResult = false; try { removeResult = cache.remove(aceKey); } catch (IllegalArgumentException | IllegalStateException | CacheException e) { logger.error("Remove {} failed.", cacheId, e); } return removeResult; }
Example 6
Source File: EhcacheService.java From jeecg with Apache License 2.0 | 5 votes |
@Override public boolean remove(String cacheName, Object key) { log.debug(" EhcacheService remove cacheName: [{}] , key: [{}]",cacheName,key); Cache cache = manager.getCache(cacheName); if (cache != null) { return cache.remove(key); } return false; }
Example 7
Source File: EhcacheTest.java From blog with BSD 2-Clause "Simplified" License | 4 votes |
public static void main(String[] args) { try { // 创建一个CacheManager实例 CacheManager manager = new CacheManager(); // 增加一个cache manager.addCache("cardCache"); // 获取所有cache名称 String[] cacheNamesForManager = manager.getCacheNames(); int iLen = cacheNamesForManager.length; System.out.println("缓存名称列表:----------------------------"); for (int i = 0; i < iLen; i++) { System.out.println(cacheNamesForManager[i].toString()); } // 获取cache对象 Cache cache = manager.getCache("cardCache"); // create Element element = new Element("username", "howsky"); cache.put(element); // get Element element_get = cache.get("username"); Object value = element_get.getObjectValue(); System.out.println(value.toString()); Element element_get2 = cache.get("username"); System.out.println(element_get2==element_get); // update cache.put(new Element("username", "howsky.net")); // get Element element_new = cache.get("username"); System.out.println(element_new==element_get); Object value_new = element_new.getObjectValue(); System.out.println(value_new.toString()); cache.remove("username"); // 移除cache manager.removeCache("cardCache"); // 关闭CacheManager manager.shutdown(); } catch (Exception e) { System.out.println(e.getMessage()); } }
Example 8
Source File: EhcacheApiTest.java From spring-tutorial with Creative Commons Attribution Share Alike 4.0 International | 4 votes |
/** * 使用Ehcache默认配置(classpath下的ehcache.xml)获取单例的CacheManager实例 */ @Test public void operation() { CacheManager manager = CacheManager.newInstance("src/test/resources/ehcache/ehcache.xml"); // 获得Cache的引用 Cache cache = manager.getCache("users"); // 将一个Element添加到Cache cache.put(new Element("key1", "value1")); // 获取Element,Element类支持序列化,所以下面两种方法都可以用 Element element1 = cache.get("key1"); // 获取非序列化的值 System.out.println("key=" + element1.getObjectKey() + ", value=" + element1.getObjectValue()); // 获取序列化的值 System.out.println("key=" + element1.getKey() + ", value=" + element1.getValue()); // 更新Cache中的Element cache.put(new Element("key1", "value2")); Element element2 = cache.get("key1"); System.out.println("key=" + element2.getObjectKey() + ", value=" + element2.getObjectValue()); // 获取Cache的元素数 System.out.println("cache size:" + cache.getSize()); // 获取MemoryStore的元素数 System.out.println("MemoryStoreSize:" + cache.getMemoryStoreSize()); // 获取DiskStore的元素数 System.out.println("DiskStoreSize:" + cache.getDiskStoreSize()); // 移除Element cache.remove("key1"); System.out.println("cache size:" + cache.getSize()); // 关闭当前CacheManager对象 manager.shutdown(); // 关闭CacheManager单例实例 CacheManager.getInstance().shutdown(); }