Java 类net.sf.ehcache.Element 实例源码

项目:forweaver2.0    文件:WeaverService.java   
/** 비밀번호를 재발급을 위한 메서드
 * @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;
}
项目:cas-server-4.2.1    文件:EhCacheTicketRegistry.java   
@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;
}
项目:forweaver2.0    文件:PostService.java   
/** 글 추천하면 캐시에 저장하고 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;
}
项目:forweaver2.0    文件:RepositoryService.java   
/** 저장소를 추천하면 캐시에 저장하고 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;
}
项目:dble    文件:EnchachePool.java   
@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;
    }
}
项目:parabuild-ci    文件:EhCache.java   
/**
 * 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);
    }
}
项目:cas-server-4.2.1    文件:CRLDistributionPointRevocationChecker.java   
@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);
    }
}
项目:Spring-5.0-Cookbook    文件:CacheListenerAspect.java   
@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();
   }
}
项目:springboot-shiro-cas-mybatis    文件:EhcacheBackedMap.java   
@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;

}
项目:springboot-shiro-cas-mybatis    文件:CRLDistributionPointRevocationChecker.java   
@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);
    }
}
项目:cas-5.1.0    文件:EhCacheMonitorTests.java   
@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());
}
项目:otus_java_2017_04    文件:EhcaheMain.java   
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());
}
项目:smart-cache    文件:CacheTemplate.java   
/**
 * 判断缓存是否存在(根据缓存层级)
 */
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;
}
项目:mycat-src-1.6.1-RELEASE    文件:EnchachePool.java   
@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;
    }
}
项目:forweaver2.0    文件:WeaverService.java   
/** 인증된 키를 통해 재발급된 비밀번호로 변경하는 메서드
 * @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;
}
项目:forweaver2.0    文件:DataService.java   
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();
}
项目:product    文件:OsService.java   
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();
}
项目:crm    文件:ProductService.java   
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();
}
项目:parabuild-ci    文件:ErrorManagerImpl.java   
/**
 * 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;
}
项目:product    文件:LanguageService.java   
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();
}
项目:product    文件:TargetService.java   
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;
}
项目:shuzheng    文件:EhCacheUtil.java   
/**
 * 新增缓存记录
 * @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);
    }
}
项目:product    文件:AporialevelService.java   
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;
}
项目:product    文件:AporialevelService.java   
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();
}
项目:product    文件:CodeService.java   
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;
}
项目:product    文件:CodeService.java   
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();
}
项目:product    文件:StudioService.java   
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;
}
项目:product    文件:StudioService.java   
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();
}
项目:rure    文件:EhCacheUtil.java   
/**
 * 新增缓存记录
 * @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);
    }
}
项目:product    文件:TechnicalpointService.java   
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();
}
项目:bdf2    文件:ApplicationCacheImpl.java   
public Object getCacheObject(String key){
    Element objElement=bdfCache.get(buildKey(key));
    if(objElement!=null){
        return objElement.getObjectValue();
    }
    return null;
}
项目:product    文件:FuncService.java   
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();
}
项目:kaltura-ce-sakai-extension    文件:KalturaAPIService.java   
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;
}
项目:product    文件:ProductService.java   
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();
}
项目:crm    文件:LinkmanService.java   
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;
}
项目:product    文件:JinduService.java   
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;
}
项目:zheng-lite    文件:EhCacheUtil.java   
/**
 * 获取缓存记录
 * @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();
}
项目:product    文件:PublishService.java   
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;
}
项目:bdf2    文件:ApplicationCacheImpl.java   
public Object getCacheObject(String key){
    Element objElement=bdfCache.get(buildKey(key));
    if(objElement!=null){
        return objElement.getObjectValue();
    }
    return null;
}
项目:xsharing-services-router    文件:EhCacheWrapper.java   
@SuppressWarnings("unchecked")
public VALUE get(KEY key) {
    Element e = cache.get(key);

    if (e == null) {
        return null;
    }
    return (VALUE) e.getObjectValue();
}