net.sf.ehcache.Cache.get()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(242)

本文整理了Java中net.sf.ehcache.Cache.get()方法的一些代码示例,展示了Cache.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.get()方法的具体详情如下:
包路径:net.sf.ehcache.Cache
类名称:Cache
方法名:get

Cache.get介绍

[英]Gets an element from the cache. Updates Element Statistics

Note that the Element's lastAccessTime is always the time of this get. Use #getQuiet(Object) to peak into the Element to see its last access time with get

Synchronization is handled within the method.
[中]从缓存中获取元素。更新元素统计信息
请注意,元素的lastAccessTime始终是此get的时间。使用#getQuiet(Object)到达元素的峰值,查看其使用get的最后访问时间
同步是在方法中处理的。

代码示例

代码示例来源:origin: ninjaframework/ninja

public Object get(String key) {
  Element e = ehCache.get(key);
  return (e == null) ? null : e.getObjectValue();
}

代码示例来源:origin: shuzheng/zheng

/**
 * 获取缓存记录
 * @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();
}

代码示例来源:origin: jfinal/jfinal

@SuppressWarnings("unchecked")
public static <T> T get(String cacheName, Object key) {
  Element element = getOrAddCache(cacheName).get(key);
  return element != null ? (T)element.getObjectValue() : null;
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
public Object getHydratedCacheElementItem(String cacheRegion, String cacheName, Serializable elementKey, String elementItemName) {
  Object response = null;
  Element element;
  String myKey = cacheRegion + '_' + cacheName + '_' + elementItemName + '_' + elementKey;
  element = getHeap().get(myKey);
  if (element != null) {
    response = element.getObjectValue();
  }
  return response;
}

代码示例来源:origin: stylefeng/Guns

@SuppressWarnings("all")
public static <T> T get(String cacheName, Object key) {
  Element element = getOrAddCache(cacheName).get(key);
  if (element == null) {
    return null;
  } else {
    Object objectValue = element.getObjectValue();
    return (T) objectValue;
  }
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected Date getCachedDate(final String key) {
  final Element element = getUriCachedDateCache().get(key);
  final Date cachedDate;
  if (element != null && element.getObjectValue() != null) {
    cachedDate = (Date) element.getObjectValue();
  } else {
    cachedDate = new Date();
  }
  return cachedDate;
}

代码示例来源:origin: Dreampie/Resty

public <T> T getCache(String group, String key) {
 try {
  createIfMissing(group);
  Cache c = cacheManager.getCache(group);
  return (T) (c.get(key) == null ? null : c.get(key).getObjectValue());
 } catch (Exception e) {
  logger.warn("%s", e, e);
  return null;
 }
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected static Map<String, Translation> getThreadlocalCache() {
  long threadId = Thread.currentThread().getId();
  Element cacheElement = getCache().get(threadId);
  return cacheElement == null ? null : (Map<String, Translation>) cacheElement.getObjectValue();
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected URLHandler getUrlHandlerFromCache(String key) {
  Element cacheElement = getUrlHandlerCache().get(key);
  if (cacheElement != null) {
    return (URLHandler) cacheElement.getObjectValue();
  }
  return null;
}

代码示例来源:origin: primefaces/primefaces

@Override
public Object get(String region, String key) {
  Cache cacheRegion = getRegion(region);
  Element element = cacheRegion.get(key);
  if (element != null) {
    return element.getObjectValue();
  }
  else {
    return null;
  }
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
public Object getHydratedCacheElementItem(String cacheRegion, String cacheName, Serializable elementKey, String elementItemName) {
  Element element;
  String myKey = cacheRegion + '_' + cacheName + '_' + elementItemName + '_' + elementKey;
  if (removeKeys.contains(myKey)) {
    return null;
  }
  Object response = null;
  element = getHeap().get(myKey);
  if (element != null) {
    response = element.getObjectValue();
  }
  return response;
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected boolean isNullPageCached(Locale locale, String uri, boolean secure) {
  boolean result = false;
  final String cacheKey = buildKey(uri, locale, secure);
  if (getPageCache().get(cacheKey) != null) {
    Object pageDto = ((List) this.getPageCache().get(cacheKey).getObjectValue()).get(0);
    if (pageDto instanceof NullPageDTO) {
      result = true;
    }
  }
  return result;
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected String getPropertyFromCache(String propertyName) {
  String key = buildKey(propertyName);
  Element cacheElement = getSystemPropertyCache().get(key);
  if (cacheElement != null && cacheElement.getObjectValue() != null) {
    return (String) cacheElement.getObjectValue();
  }
  return null;
}

代码示例来源:origin: ninjaframework/ninja

public synchronized long incr(String key, int by) {
  Element e = ehCache.get(key);
  if (e == null) {
    return -1;
  }
  long newValue = ((Number) e.getObjectValue()).longValue() + by;
  Element newE = new Element(key, newValue);
  newE.setTimeToLive(e.getTimeToLive());
  ehCache.put(newE);
  return newValue;
}

代码示例来源:origin: ninjaframework/ninja

public synchronized long decr(String key, int by) {
  Element e = ehCache.get(key);
  if (e == null) {
    return -1;
  }
  long newValue = ((Number) e.getObjectValue()).longValue() - by;
  Element newE = new Element(key, newValue);
  newE.setTimeToLive(e.getTimeToLive());
  ehCache.put(newE);
  return newValue;
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
public Boolean removeURLHandlerFromCache(String mapKey) {
  Boolean success = Boolean.FALSE;
  if (mapKey != null) {
    Element e = getUrlHandlerCache().get(mapKey);
    if (e != null && e.getObjectValue() != null) {
      success = Boolean.valueOf(getUrlHandlerCache().remove(mapKey));
    }
  }
  return success;
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
public boolean isUserQualifiedForOperationOnCeilingEntity(AdminUser adminUser, PermissionType permissionType, String ceilingEntityFullyQualifiedName) {
  Boolean response = null;
  String cacheKey = buildCacheKey(adminUser, permissionType, ceilingEntityFullyQualifiedName);
  Element cacheElement = cache.get(cacheKey);
  if (cacheElement != null) {
    response = (Boolean) cacheElement.getObjectValue();
    if (LOG.isTraceEnabled()) {
      LOG.trace("Admin Security Cache GET For: \"" + cacheKey + "\" = " + response);
    }
  }
  
  if (response == null) {
    response = adminPermissionDao.isUserQualifiedForOperationOnCeilingEntity(adminUser, permissionType, ceilingEntityFullyQualifiedName);
    if (!response) {
      response = adminPermissionDao.isUserQualifiedForOperationOnCeilingEntityViaDefaultPermissions(ceilingEntityFullyQualifiedName);
    }
    cacheElement = new Element(cacheKey, response);
    cache.put(cacheElement);
    if (LOG.isTraceEnabled()) {
      LOG.trace("Admin Security Cache PUT For: \"" + cacheKey + "\" = " + response);
    }
  }
  
  return response;
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@SuppressWarnings("unchecked")
protected void addPageMapCacheEntry(String identifier, String key) {
  BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
  Site site = context.getNonPersistentSite();
  Long siteId = (site != null) ? site.getId() : null;
  String mapKey = getPageMapCacheKey(identifier, siteId);
  if (mapKey != null) {
    Element e = getPageMapCache().get(mapKey);
    if (e == null || e.getObjectValue() == null) {
      List<String> keys = new ArrayList<>();
      keys.add(key);
      getPageMapCache().put(new Element(mapKey, keys));
    } else {
      ((List<String>) e.getObjectValue()).add(mapKey);
    }
  }
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@SuppressWarnings("unchecked")
protected List<PageDTO> getPageListFromCache(String key) {
  if (key != null) {
    Element cacheElement = getPageCache().get(key);
    if (cacheElement != null && cacheElement.getObjectValue() != null) {
      statisticsService.addCacheStat(CacheStatType.PAGE_CACHE_HIT_RATE.toString(), true);
      return (List<PageDTO>) cacheElement.getObjectValue();
    }
    statisticsService.addCacheStat(CacheStatType.PAGE_CACHE_HIT_RATE.toString(), false);
  }
  return null;
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
public List<StructuredContentDTO> getStructuredContentListFromCache(String key) {
  Element scElement = getStructuredContentCache().get(key);
  if (scElement != null) {
    statisticsService.addCacheStat(CacheStatType.STRUCTURED_CONTENT_CACHE_HIT_RATE.toString(), true);
    return (List<StructuredContentDTO>) scElement.getObjectValue();
  }
  statisticsService.addCacheStat(CacheStatType.STRUCTURED_CONTENT_CACHE_HIT_RATE.toString(), false);
  return null;
}

相关文章

Cache类方法