/** 비밀번호를 재발급을 위한 메서드 * @param email * @return 성공여부 */ public boolean sendRepassword(String email){ Cache rePasswordCache = cacheManager.getCache("repassword"); Object object = rePasswordCache.get(email); if(object != null || weaverDao.get(email) == null) //등록된 이메일이 없을 경우. return false; String password = KeyGenerators.string().generateKey().substring(0, 7); String key = passwordEncoder.encodePassword(password, null); RePassword rePassword = new RePassword(key, password); mailUtil.sendMail(email,"[forweaver] 비밀번호 재발급", "링크 - http://forweaver.com/repassword/"+email+"/"+key+"\n"+ "변경된 비밀번호 - "+password+"\n"+ "\n링크에 5분이내에 접속하시고 나서 변경된 비밀번호로 로그인해주세요!"); Element newElement = new Element(email, rePassword); rePasswordCache.put(newElement); return true; }
@Override public Ticket getTicket(final String ticketIdToGet) { final String ticketId = encodeTicketId(ticketIdToGet); if (ticketId == null) { return null; } Element element = this.serviceTicketsCache.get(ticketId); if (element == null) { element = this.ticketGrantingTicketsCache.get(ticketId); } if (element == null) { logger.debug("No ticket by id [{}] is found in the registry", ticketId); return null; } final Ticket proxiedTicket = decodeTicket((Ticket) element.getObjectValue()); final Ticket ticket = getProxiedTicketInstance(proxiedTicket); return ticket; }
/** 글 추천하면 캐시에 저장하고 24시간 제한을 둠. * @param post * @param weaver * @return */ public boolean push(Post post, Weaver weaver,String ip) { if (weaver != null && weaver.equals(post.getWriter())) return false; Cache cache = cacheManager.getCache("push"); // 중복 추천 방지! Element element = cache.get(post.getPostID()+"@@"+ip); if (element == null || (element != null && element.getValue() == null)) { post.push(); postDao.update(post); Element newElement = new Element(post.getPostID()+"@@"+ip, ip); cache.put(newElement); return true; } return false; }
/** 저장소를 추천하면 캐시에 저장하고 24시간 제한을 둠. * @param repository * @param weaver * @param ip * @return */ public boolean push(Repository repository, Weaver weaver,String ip) { if(repository == null || repository.getAuthLevel() > 0 || (weaver == null && repository.isJoinWeaver(weaver))) return false; Cache cache = cacheManager.getCache("push"); Element element = cache.get(repository.getName()+"@@"+ip); if (element == null || (element != null && element.getValue() == null)) { repository.push(); repositoryDao.update(repository); Element newElement = new Element(repository.getName()+"@@"+ip, ip); cache.put(newElement); return true; } return false; }
@Override public Object get(Object key) { Element cacheEl = enCache.get(key); if (cacheEl != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(name + " hit cache ,key:" + key); } cacheStatistics.incHitTimes(); return cacheEl.getObjectValue(); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug(name + " miss cache ,key:" + key); } cacheStatistics.incAccessTimes(); return null; } }
/** * 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 * @throws CacheException */ public Object get(Object key) throws CacheException { try { if ( log.isDebugEnabled() ) { log.debug("key: " + key); } if (key == null) { return null; } else { Element element = cache.get( (Serializable) key ); if (element == null) { if ( log.isDebugEnabled() ) { log.debug("Element for " + key + " is null"); } return null; } else { return element.getValue(); } } } catch (net.sf.ehcache.CacheException e) { throw new CacheException(e); } }
@Override protected boolean addCRL(final Object id, final X509CRL crl) { try { if (crl == null) { logger.debug("No CRL was passed. Removing {} from cache...", id); return this.crlCache.remove(id); } this.crlCache.put(new Element(id, crl.getEncoded())); return this.crlCache.get(id) != null; } catch (final Exception e) { logger.warn("Failed to add the crl entry [{}] to the cache", crl); throw new RuntimeException(e); } }
@Around("execution(* org.packt.aop.transaction.dao.impl.EmployeeDaoImpl.getEmployees(..))") public Object cacheMonitor(ProceedingJoinPoint joinPoint) throws Throwable { logger.info("executing " + joinPoint.getSignature().getName()); Cache cache = cacheManager.getCache("employeesCache"); logger.info("cache detected is " + cache.getName()); logger.info("begin caching....."); String key = joinPoint.getSignature().getName(); logger.info(key); if(cache.get(key) == null){ logger.info("caching new Object....."); Object result = joinPoint.proceed(); cache.put(new Element(key, result)); return result; }else{ logger.info("getting cached Object....."); return cache.get(key).getObjectValue(); } }
@Override public Set<Entry<String, String>> entrySet() { final Set<String> keys = keySet(); final Set<Entry<String, String>> entries = new HashSet<>(); for (final String key : keys) { final Element element = this.cache.get(key); if (element != null) { entries.add(new ElementMapEntry(element)); } } return entries; }
@Test public void verifyObserve() throws Exception { CacheStatus status = CacheStatus.class.cast(monitor.observe()); CacheStatistics stats = status.getStatistics()[0]; assertEquals(100, stats.getCapacity()); assertEquals(0, stats.getSize()); assertEquals(StatusCode.OK, status.getCode()); // Fill cache 95% full, which is above 10% free WARN threshold IntStream.range(0, 95).forEach(i -> cache.put(new Element("key" + i, "value" + i))); status = CacheStatus.class.cast(monitor.observe()); stats = status.getStatistics()[0]; assertEquals(100, stats.getCapacity()); assertEquals(95, stats.getSize()); assertEquals(StatusCode.WARN, status.getCode()); // Exceed the capacity and force evictions which should report WARN status IntStream.range(95, 110).forEach(i -> cache.put(new Element("key" + i, "value" + i))); status = CacheStatus.class.cast(monitor.observe()); stats = status.getStatistics()[0]; assertEquals(100, stats.getCapacity()); assertEquals(100, stats.getSize()); assertEquals(StatusCode.WARN, status.getCode()); }
private void idleExample() throws InterruptedException { System.out.println("\nIdle example\n"); Cache testCache = EhcacheHelper.createIdleCache(manager, "idleCache"); testCache.put(new Element(0, "String: 0")); testCache.get(0); System.out.println("Hit count: " + testCache.getStatistics().cacheHitCount()); System.out.println("Miss count: " + testCache.getStatistics().cacheMissCount()); Thread.sleep(TimeUnit.SECONDS.toMillis(EhcacheHelper.IDLE_TIME_SEC) - 1); testCache.get(0); System.out.println("Hit count: " + testCache.getStatistics().cacheHitCount()); System.out.println("Miss count: " + testCache.getStatistics().cacheMissCount()); Thread.sleep(TimeUnit.SECONDS.toMillis(EhcacheHelper.IDLE_TIME_SEC) + 1); testCache.get(0); System.out.println("Hit count: " + testCache.getStatistics().cacheHitCount()); System.out.println("Miss count: " + testCache.getStatistics().cacheMissCount()); }
/** * 判断缓存是否存在(根据缓存层级) */ public boolean exists(String name, String key, Level level) { boolean flag = false; if (level.equals(Level.Local)) { if (this.ehcaches.containsKey(name)) { Element element = this.getEhcache(name).get(key); flag = element != null; } } else { flag = this.jedisTemplate.exists(this.getRedisKeyOfElement(name, key)); } if (logger.isDebugEnabled()) { logger.debug("exists > name:" + name + ",key:" + key + ",level:" + level + ",exists:" + flag); } return flag; }
@Override public Object get(Object key) { Element cacheEl = enCache.get(key); if (cacheEl != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(name+" hit cache ,key:" + key); } cacheStati.incHitTimes(); return cacheEl.getObjectValue(); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug(name+" miss cache ,key:" + key); } cacheStati.incAccessTimes(); return null; } }
/** 인증된 키를 통해 재발급된 비밀번호로 변경하는 메서드 * @param email * @param key * @return 성공여부 */ public boolean changePassword(String email,String key){ Cache rePasswordCache = cacheManager.getCache("repassword"); Element element = rePasswordCache.get(email); if(element == null) return false; RePassword rePassword = (RePassword)element.getValue(); if(rePassword.getKey().equals(key)){ Weaver weaver = weaverDao.get(email); weaver.setPassword(passwordEncoder.encodePassword(rePassword.getPassword(),null)); weaverDao.update(weaver); } return true; }
public String getObjectID(String dataName,Weaver weaver){ Cache tmpNameCache = cacheManager.getCache("tmpName"); dataName = dataName.replace(" ", "_"); dataName = dataName.replace("?", "_"); dataName = dataName.replace("#", "_"); dataName = dataName.trim(); Element element = tmpNameCache.get(weaver.getId()+"/"+dataName); if(element == null) return ""; return (String)element.getValue(); }
public int listCount(Condition c) { Long num = 0L; Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(CACHE_COUNT_KEY) == null) { num = Long.valueOf(this.count(c)); cache.put(new Element(CACHE_COUNT_KEY, num)); }else{ num = (Long)cache.get(CACHE_COUNT_KEY).getObjectValue(); } return num.intValue(); }
public int listCount(Cnd c) { Long num = 0L; Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(CACHE_COUNT_KEY) == null) { num = Long.valueOf(this.count(c)); cache.put(new Element(CACHE_COUNT_KEY, num)); }else{ num = (Long)cache.get(CACHE_COUNT_KEY).getObjectValue(); } return num.intValue(); }
/** * Returns true if error was reported withing retention period */ private boolean isErrorReported(final Error error) { boolean result; try { // calculate error hash final RetentionCache cache = getRetentionCache(); final Element elem = cache.get(error.getRetentionKey()); result = elem != null; } catch (CacheException e) { logHard("Error while checking error retention, will return false", e); result = false; } return result; }
public List<Target> queryCache(Condition c,Page p) { List<Target> list_target = null; String cacheKey = "target_list_" + p.getPageCurrent(); Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(cacheKey) == null) { list_target = this.query(c, p); cache.put(new Element(cacheKey, list_target)); }else{ list_target = (List<Target>)cache.get(cacheKey).getObjectValue(); } return list_target; }
/** * 新增缓存记录 * @param cacheName * @param key * @param value */ public static void put(String cacheName, String key, Object value) { Cache cache = getCache(cacheName); if (null != cache) { Element element = new Element(key, value); cache.put(element); } }
public List<Aporialevel> queryCache(Condition c,Page p) { List<Aporialevel> list_aporialevel = null; String cacheKey = "aporialevel_list_" + p.getPageCurrent(); Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(cacheKey) == null) { list_aporialevel = this.query(c, p); cache.put(new Element(cacheKey, list_aporialevel)); }else{ list_aporialevel = (List<Aporialevel>)cache.get(cacheKey).getObjectValue(); } return list_aporialevel; }
public List<Code> queryCache(Condition c,Page p) { List<Code> list_code = null; String cacheKey = "code_list_" + p.getPageCurrent(); Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(cacheKey) == null) { list_code = this.query(c, p); cache.put(new Element(cacheKey, list_code)); }else{ list_code = (List<Code>)cache.get(cacheKey).getObjectValue(); } return list_code; }
public List<Studio> queryCache(Condition c,Page p) { List<Studio> list_studio = null; String cacheKey = "studio_list_" + p.getPageCurrent(); Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(cacheKey) == null) { list_studio = this.query(c, p); cache.put(new Element(cacheKey, list_studio)); }else{ list_studio = (List<Studio>)cache.get(cacheKey).getObjectValue(); } return list_studio; }
public Object getCacheObject(String key){ Element objElement=bdfCache.get(buildKey(key)); if(objElement!=null){ return objElement.getObjectValue(); } return null; }
private KalturaCategory getCategoryfromCache(String categoryName, int parentId) { KalturaCategory cat = null; String cacheKey = parentId+":"+categoryName; Element el = categoriesCache.get(cacheKey); if (el != null) { // get it from the cache first Integer categoryId = (Integer) el.getObjectValue(); el = categoriesCache.get("id:"+categoryId); if (el != null) { cat = (KalturaCategory) el.getObjectValue(); } } return cat; }
public List<Linkman> queryCache(Cnd c,Page p) { List<Linkman> list_linkman = null; String cacheKey = "linkman_list_" + p.getPageCurrent(); Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(cacheKey) == null) { list_linkman = this.query(c, p); cache.put(new Element(cacheKey, list_linkman)); }else{ list_linkman = (List<Linkman>)cache.get(cacheKey).getObjectValue(); } return list_linkman; }
public List<Jindu> queryCache(Cnd c,Page p) { List<Jindu> list_jindu = null; String cacheKey = "jindu_list_" + p.getPageCurrent(); Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(cacheKey) == null) { list_jindu = this.query(c, p); cache.put(new Element(cacheKey, list_jindu)); }else{ list_jindu = (List<Jindu>)cache.get(cacheKey).getObjectValue(); } return list_jindu; }
/** * 获取缓存记录 * @param cacheName * @param key * @return */ public static Object get(String cacheName, String key) { Cache cache = getCache(cacheName); if (null == cache) { return null; } Element cacheElement = cache.get(key); if (null == cacheElement) { return null; } return cacheElement.getObjectValue(); }
public List<Publish> queryCache(Cnd c,Page p) { List<Publish> list_publish = null; String cacheKey = "publish_list_" + p.getPageCurrent(); Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); if(cache.get(cacheKey) == null) { list_publish = this.query(c, p); cache.put(new Element(cacheKey, list_publish)); }else{ list_publish = (List<Publish>)cache.get(cacheKey).getObjectValue(); } return list_publish; }
@SuppressWarnings("unchecked") public VALUE get(KEY key) { Element e = cache.get(key); if (e == null) { return null; } return (VALUE) e.getObjectValue(); }