本文整理汇总了Java中net.sf.ehcache.Element.setTimeToLive方法的典型用法代码示例。如果您正苦于以下问题:Java Element.setTimeToLive方法的具体用法?Java Element.setTimeToLive怎么用?Java Element.setTimeToLive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.ehcache.Element
的用法示例。
在下文中一共展示了Element.setTimeToLive方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addTicket
import net.sf.ehcache.Element; //导入方法依赖的package包/类
@Override
public void addTicket(final Ticket ticketToAdd) {
final Ticket ticket = encodeTicket(ticketToAdd);
final Element element = new Element(ticket.getId(), ticket);
int idleValue = ticketToAdd.getExpirationPolicy().getTimeToIdle().intValue();
if (idleValue <= 0) {
idleValue = ticketToAdd.getExpirationPolicy().getTimeToLive().intValue();
}
if (idleValue <= 0) {
idleValue = Integer.MAX_VALUE;
}
element.setTimeToIdle(idleValue);
int aliveValue = ticketToAdd.getExpirationPolicy().getTimeToLive().intValue();
if (aliveValue <= 0) {
aliveValue = Integer.MAX_VALUE;
}
element.setTimeToLive(aliveValue);
LOGGER.debug("Adding ticket [{}] to the cache [{}] to live [{}] seconds and stay idle for [{}] seconds",
ticket.getId(), this.ehcacheTicketsCache.getName(), aliveValue, idleValue);
this.ehcacheTicketsCache.put(element);
}
示例2: put
import net.sf.ehcache.Element; //导入方法依赖的package包/类
@Override
public void put(String cacheName, Object key, Object value, int liveSeconds) {
if (liveSeconds <= 0) {
put(cacheName, key, value);
return;
}
Element element = new Element(key, value);
element.setTimeToLive(liveSeconds);
getOrAddCache(cacheName).put(element);
}
示例3: setTtl
import net.sf.ehcache.Element; //导入方法依赖的package包/类
@Override
public void setTtl(String cacheName, Object key, int seconds) {
Element element = getOrAddCache(cacheName).get(key);
if (element == null) {
return;
}
element.setTimeToLive(seconds);
getOrAddCache(cacheName).put(element);
}
示例4: add
import net.sf.ehcache.Element; //导入方法依赖的package包/类
@Override
public void add(String key, Object value, int expires, String group) {
net.sf.ehcache.Cache cacher = cacher(group);
if (cacher != null) {
Element element = new Element(key, value);
element.setTimeToLive(expires);
cacher.put(element);
}
}
示例5: create
import net.sf.ehcache.Element; //导入方法依赖的package包/类
public StoreEntry create(Key key, int timeToLive) {
StoreEntryImpl result = new StoreEntryImpl(timeToLive);
Element element = new Element(key, result);
element.setTimeToLive(timeToLive);
cache.put(element);
return result;
}
示例6: incr
import net.sf.ehcache.Element; //导入方法依赖的package包/类
@Override
public synchronized long incr(String key, String group, int by) {
net.sf.ehcache.Cache cacher = cacher(group);
if (cacher != null) {
Element element = cacher.get(key);
if (element == null) {
return -1;
}
long newValue = ((Number)element.getObjectValue()).longValue() + by;
Element newEle = new Element(key, newValue);
newEle.setTimeToLive(element.getTimeToLive());
cacher.put(newEle);
return newValue;
}
return -1;
}
示例7: decr
import net.sf.ehcache.Element; //导入方法依赖的package包/类
@Override
public synchronized long decr(String key, String group, int by) {
net.sf.ehcache.Cache cacher = cacher(group);
if (cacher != null) {
Element element = cacher.get(key);
if (element == null) {
return -1;
}
long newValue = ((Number)element.getObjectValue()).longValue() - by;
Element newEle = new Element(key, newValue);
newEle.setTimeToLive(element.getTimeToLive());
cacher.put(newEle);
return newValue;
}
return -1;
}