/** * Constructor * * @param key any non null value * @param value any value, including nulls * @param timeToIdleSeconds seconds to idle * @param timeToLiveSeconds seconds to live * @since 2.7.1 */ public Element(final Object key, final Object value, final int timeToIdleSeconds, final int timeToLiveSeconds) { this(key, value); setTimeToIdle(timeToIdleSeconds); setTimeToLive(timeToLiveSeconds); }
/** * Constructor used by ehcache-server * * timeToIdleSeconds and timeToLiveSeconds will have precedence over eternal. Which means that what ever eternal says, non-null * timeToIdleSeconds or timeToLiveSeconds will result in the element not being eternal * * @param key any non null value * @param value any value, including nulls * @param eternal specify as non-null to override cache configuration * @param timeToIdleSeconds specify as non-null to override cache configuration * @param timeToLiveSeconds specify as non-null to override cache configuration * * @deprecated */ @Deprecated public Element(final Object key, final Object value, final Boolean eternal, final Integer timeToIdleSeconds, final Integer timeToLiveSeconds) { this.key = key; this.value = value; if (eternal != null) { setEternal(eternal.booleanValue()); } if (timeToIdleSeconds != null) { setTimeToIdle(timeToIdleSeconds.intValue()); } if (timeToLiveSeconds != null) { setTimeToLive(timeToLiveSeconds.intValue()); } this.creationTime = getCurrentTime(); }
public void setTimeToIdleSeconds(int timeToIdle) { element.setTimeToIdle(timeToIdle); }
public void setTimeToIdleSeconds(int timeToIdle) { element.setTimeToIdle(timeToIdle); }
public void setTimeToIdleSeconds(int timeToIdle) { element.setTimeToIdle(timeToIdle); }
public void setTimeToIdleSeconds(int timeToIdle) { element.setTimeToIdle(timeToIdle); }
/** * Constructor * * @param key any non null value * @param value any value, including nulls * @param timeToIdleSeconds seconds to idle * @param timeToLiveSeconds seconds to live * @since 2.7.1 */ public Element(final Object key, final Object value, final int timeToIdleSeconds, final int timeToLiveSeconds) { this(key, value); setTimeToIdle(timeToIdleSeconds); setTimeToLive(timeToLiveSeconds); }
/** * Constructor * * @param key any non null value * @param value any value, including nulls * @param timeToIdleSeconds seconds to idle * @param timeToLiveSeconds seconds to live * @since 2.7.1 */ public Element(final Object key, final Object value, final int timeToIdleSeconds, final int timeToLiveSeconds) { this(key, value); setTimeToIdle(timeToIdleSeconds); setTimeToLive(timeToLiveSeconds); }
public void setRequestState(String relayState, RequestState state) { if (relayState == null || "".equals(relayState)) { return; } int parsedTTL = (int)ttl; if (ttl != parsedTTL) { // Fall back to 60 minutes if the default TTL is set incorrectly parsedTTL = 3600; } Element element = new Element(relayState, state); element.setTimeToLive(parsedTTL); element.setTimeToIdle(parsedTTL); requestCache.put(element); }
public void setResponseState(String securityContextKey, ResponseState state) { if (securityContextKey == null || "".equals(securityContextKey)) { return; } int parsedTTL = (int)ttl; if (ttl != parsedTTL) { // Fall back to 5 minutes if the default TTL is set incorrectly parsedTTL = 60 * 5; } Element element = new Element(securityContextKey, state); element.setTimeToLive(parsedTTL); element.setTimeToIdle(parsedTTL); responseCache.put(element); }
/** * Constructor used by ehcache-server * * @param key any non null value * @param value any value, including nulls * @param eternal specify as non-null to override cache configuration * @param timeToIdleSeconds specify as non-null to override cache configuration * @param timeToLiveSeconds specify as non-null to override cache configuration */ public Element(final Object key, final Object value, final Boolean eternal, final Integer timeToIdleSeconds, final Integer timeToLiveSeconds) { this.key = key; this.value = value; if (eternal != null) { setEternal(eternal.booleanValue()); } if (timeToIdleSeconds != null) { setTimeToIdle(timeToIdleSeconds.intValue()); } if (timeToLiveSeconds != null) { setTimeToLive(timeToLiveSeconds.intValue()); } this.elementEvictionData = new DefaultElementEvictionData(System.currentTimeMillis()); }
/** * Constructor used by ehcache-server * * timeToIdleSeconds and timeToLiveSeconds will have precedence over eternal. Which means that what ever eternal says, non-null * timeToIdleSeconds or timeToLiveSeconds will result in the element not being eternal * * @param key any non null value * @param value any value, including nulls * @param eternal specify as non-null to override cache configuration * @param timeToIdleSeconds specify as non-null to override cache configuration * @param timeToLiveSeconds specify as non-null to override cache configuration * * @deprecated */ @Deprecated public Element(final Object key, final Object value, final Boolean eternal, final Integer timeToIdleSeconds, final Integer timeToLiveSeconds) { this.key = key; this.value = value; if (eternal != null) { setEternal(eternal.booleanValue()); } if (timeToIdleSeconds != null) { setTimeToIdle(timeToIdleSeconds.intValue()); } if (timeToLiveSeconds != null) { setTimeToLive(timeToLiveSeconds.intValue()); } this.creationTime = getCurrentTime(); }
private void applyDefaultsToElementWithoutLifespanSet(Element element) { if (!element.isLifespanSet()) { // Setting with Cache defaults // Eternal is always false element.setTimeToLive((int) timeToLiveSeconds); element.setTimeToIdle((int) timeToIdleSeconds); element.setEternal(false); } }
private void applyDefaultsToElementWithoutLifespanSet(Element element) { if (!element.isLifespanSet()) { // Setting with Cache defaults // Eternal is always false element.setTimeToLive((int) timeToLiveSeconds); element.setTimeToIdle((int) timeToIdleSeconds); element.setEternal(false); } }
private void applyDefaultsToElementWithoutLifespanSet(Element element) { if (!element.isLifespanSet()) { // Setting with Cache defaults // Eternal is always false element.setTimeToLive((int) timeToLiveSeconds); element.setTimeToIdle((int) timeToIdleSeconds); element.setEternal(false); } }
private void applyDefaultsToElementWithoutLifespanSet(Element element) { if (!element.isLifespanSet()) { // Setting with Cache defaults // Eternal is always false element.setTimeToLive((int) timeToLiveSeconds); element.setTimeToIdle((int) timeToIdleSeconds); element.setEternal(false); } }
private Element createElementFromBody(String key, Exchange exchange, String cacheOperation) throws NoTypeConversionAvailableException { Element element; Object body = exchange.getIn().getBody(); if (body == null) { throw new CacheException("Body cannot be null for operation " + cacheOperation); } else if (body instanceof Serializable) { element = new Element(key, body); } else if (config.isObjectCache()) { element = new Element(key, body); } else { InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, body); // Read InputStream into a byte[] buffer element = new Element(key, exchange.getContext().getTypeConverter().mandatoryConvertTo(byte[].class, is)); } // set overrides for the cache expiration and such final Integer ttl = exchange.getIn().getHeader(CacheConstants.CACHE_ELEMENT_EXPIRY_TTL, Integer.class); if (ttl != null) { element.setTimeToLive(ttl); } final Integer idle = exchange.getIn().getHeader(CacheConstants.CACHE_ELEMENT_EXPIRY_IDLE, Integer.class); if (idle != null) { element.setTimeToIdle(idle); } final Boolean flag = exchange.getIn().getHeader(CacheConstants.CACHE_ELEMENT_EXPIRY_ETERNAL, Boolean.class); if (flag != null) { element.setEternal(flag); } return element; }
private boolean setTimeTo(final boolean overrideDefaults, final Duration duration, final Element element) { if(!overrideDefaults) { return true; } if (duration != null) { if (duration.isZero()) { return false; } if (duration.isEternal()) { element.setEternal(true); } else { final int d = (int)TimeUnit.SECONDS.convert(duration.getDurationAmount(), duration.getTimeUnit()); element.setTimeToLive(d == 0 ? 1 : d); element.setTimeToIdle(d); } } return true; }
private boolean setTimeTo(final boolean overrideDefaults, final Duration duration, final Element element) { if(!overrideDefaults) { return true; } if (duration != null) { if (duration.isZero()) { return false; } if (duration.isEternal()) { element.setEternal(true); } else { final int d = (int)TimeUnit.SECONDS.convert(duration.getDurationAmount(), duration.getTimeUnit()); element.setTimeToLive(d == 0 ? 1 : d); element.setTimeToIdle(d); } } return true; }
@Override public void addTicket(final Ticket ticketToAdd) { val metadata = this.ticketCatalog.find(ticketToAdd); val ticket = encodeTicket(ticketToAdd); val element = new Element(ticket.getId(), ticket); val expirationPolicy = ticketToAdd.getExpirationPolicy(); var idleValue = expirationPolicy.getTimeToIdle().intValue(); if (idleValue <= 0) { idleValue = expirationPolicy.getTimeToLive().intValue(); } if (idleValue <= 0) { idleValue = Integer.MAX_VALUE; } element.setTimeToIdle(idleValue); var aliveValue = expirationPolicy.getTimeToLive().intValue(); if (aliveValue <= 0) { aliveValue = Integer.MAX_VALUE; } element.setTimeToLive(aliveValue); val cache = getTicketCacheFor(metadata); LOGGER.debug("Adding ticket [{}] to the cache [{}] to live [{}] seconds and stay idle for [{}] seconds", ticket.getId(), cache.getName(), aliveValue, idleValue); cache.put(element); }