本文整理了Java中net.sf.ehcache.Cache.put()
方法的一些代码示例,展示了Cache.put()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.put()
方法的具体详情如下:
包路径:net.sf.ehcache.Cache
类名称:Cache
方法名:put
[英]Put an element in the cache.
Resets the access statistics on the element, which would be the case if it has previously been gotten from a cache, and is now being put back.
Also notifies the CacheEventListener that:
Caches which use synchronous replication can throw RemoteCacheException here if the replication to the cluster fails. This exception should be caught in those circumstances.
[中]将元素放入缓存中。
重置元素上的访问统计信息,如果该元素以前是从缓存中获取的,现在又被放回缓存中,则会出现这种情况。
还通知CacheEventListener:
*元素已放置,但仅当元素已实际放置时。
*如果缓存中存在该元素,则表明已发生更新,即使请求该元素时该元素将过期
如果到群集的复制失败,则使用同步复制的缓存可以在此处引发RemoteCacheException。在这些情况下,应抓住这一例外。
代码示例来源:origin: shuzheng/zheng
/**
* 新增缓存记录
* @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);
}
}
代码示例来源:origin: ninjaframework/ninja
public void add(String key, Object value, int expiration) {
if (ehCache.get(key) != null) {
return;
}
Element element = new Element(key, value);
element.setTimeToLive(expiration);
ehCache.put(element);
}
代码示例来源:origin: ninjaframework/ninja
public void replace(String key, Object value, int expiration) {
if (ehCache.get(key) == null) {
return;
}
Element element = new Element(key, value);
element.setTimeToLive(expiration);
ehCache.put(element);
}
代码示例来源:origin: ninjaframework/ninja
public void set(String key, Object value, int expiration) {
Element element = new Element(key, value);
element.setTimeToLive(expiration);
ehCache.put(element);
}
代码示例来源:origin: jfinal/jfinal
public static void put(String cacheName, Object key, Object value) {
getOrAddCache(cacheName).put(new Element(key, value));
}
代码示例来源:origin: Dreampie/Resty
public void addCache(String group, String key, Object cache, int expired) {
createIfMissing(group);
Element element;
if (expired != -1) {
element = new Element(key, cache, false, expired, expired);
} else {
element = new Element(key, cache);
}
cacheManager.getCache(group).put(element);
}
代码示例来源:origin: primefaces/primefaces
@Override
public void put(String region, String key, Object object) {
Cache cacheRegion = getRegion(region);
cacheRegion.put(new Element(key, object));
}
代码示例来源:origin: stylefeng/Guns
public static void put(String cacheName, Object key, Object value) {
getOrAddCache(cacheName).put(new Element(key, value));
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public void addStructuredContentListToCache(String key, List<StructuredContentDTO> scDTOList) {
getStructuredContentCache().put(new Element(key, scDTOList));
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
protected void addSingleStructuredContentToCache(String key, StructuredContentDTO scDTO) {
getStructuredContentCache().put(new Element(key, scDTO));
}
代码示例来源: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 void addHydratedCacheElementItem(String cacheRegion, String cacheName, Serializable elementKey, String elementItemName, Object elementValue) {
String heapKey = cacheRegion + '_' + cacheName + '_' + elementItemName + '_' + elementKey;
String nameKey = cacheRegion + '_' + cacheName + '_' + elementKey;
Element element = new Element(heapKey, elementValue);
if (!cacheMembersByEntity.containsKey(nameKey)) {
List<String> myMembers = new ArrayList<String>(50);
myMembers.add(elementItemName);
cacheMembersByEntity.put(nameKey, myMembers);
} else {
List<String> myMembers = cacheMembersByEntity.get(nameKey);
myMembers.add(elementItemName);
}
getHeap().put(element);
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public void addHydratedCacheElementItem(String cacheRegion, String cacheName, Serializable elementKey, String elementItemName, Object elementValue) {
String heapKey = cacheRegion + '_' + cacheName + '_' + elementItemName + '_' + elementKey;
String nameKey = cacheRegion + '_' + cacheName + '_' + elementKey;
removeKeys.remove(nameKey);
Element element = new Element(heapKey, elementValue);
if (!cacheMemberNamesByEntity.containsKey(nameKey)) {
List<String> myMembers = new ArrayList<String>(50);
myMembers.add(elementItemName);
cacheMemberNamesByEntity.put(nameKey, myMembers);
} else {
List<String> myMembers = cacheMemberNamesByEntity.get(nameKey);
myMembers.add(elementItemName);
}
getHeap().put(element);
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
protected void addCachedDate(final String key) {
if (getPageCache().get(key) == null) {
getUriCachedDateCache().put(new Element(key, new Date()));
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
protected void addPropertyToCache(String propertyName, String propertyValue) {
String key = buildKey(propertyName);
if (systemPropertyCacheTimeout < 0) {
getSystemPropertyCache().put(new Element(key, propertyValue));
} else {
getSystemPropertyCache().put(new Element(key, propertyValue, systemPropertyCacheTimeout,
systemPropertyCacheTimeout));
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
public static void addToCache(List<Translation> translations) {
long threadId = Thread.currentThread().getId();
Map<String, Translation> threadlocalCache = getThreadlocalCache();
if (threadlocalCache == null) {
threadlocalCache = new HashMap<String, Translation>();
}
Map<String, Translation> additionalTranslations = BLCMapUtils.keyedMap(translations, new TypedClosure<String, Translation>() {
@Override
public String getKey(Translation translation) {
return buildCacheKey(translation);
}
});
threadlocalCache.putAll(additionalTranslations);
getCache().put(new Element(threadId, threadlocalCache));
}
代码示例来源: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
protected void addPageListToCache(List<PageDTO> pageList, String identifier, Locale locale, boolean secure) {
String key = buildKey(identifier, locale, secure);
getPageCache().put(new Element(key, pageList));
addPageMapCacheEntry(identifier, key);
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
@SuppressWarnings("unchecked")
public List<SearchFacetDTO> getSearchFacets() {
List<SearchFacetDTO> facets = null;
String cacheKey = CACHE_KEY_PREFIX + "blc-search";
Element element = cache.get(cacheKey);
if (element != null) {
facets = (List<SearchFacetDTO>) element.getValue();
}
if (facets == null) {
facets = buildSearchFacetDtos(searchFacetDao.readAllSearchFacets(FieldEntity.PRODUCT));
element = new Element(cacheKey, facets);
cache.put(element);
}
return facets;
}
内容来源于网络,如有侵权,请联系作者删除!