Beispiel #1
0
 /**
  * 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);
 }
Beispiel #2
0
  @Override
  public void addTicket(final Ticket ticketToAdd) {
    final Ticket ticket = encodeTicket(ticketToAdd);
    final Element element = new Element(ticket.getId(), ticket);

    final int idleValue = ticketToAdd.getExpirationPolicy().getTimeToIdle().intValue();
    element.setTimeToIdle(idleValue);

    final int aliveValue = ticketToAdd.getExpirationPolicy().getTimeToIdle().intValue();
    element.setTimeToLive(aliveValue);

    logger.debug(
        "Adding ticket {} to the cache {}", ticket.getId(), this.ehcacheTicketsCache.getName());
    this.ehcacheTicketsCache.put(element);
  }
Beispiel #3
0
 /**
  * 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(
     Object key,
     Object value,
     Boolean eternal,
     Integer timeToIdleSeconds,
     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());
   }
   creationTime = System.currentTimeMillis();
 }
Beispiel #4
0
 /**
  * Constructor used by ehcache-server
  *
  * <p>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();
 }
  /**
   * Tests expiry thread expiry
   *
   * @throws InterruptedException
   */
  @Test
  public void testExpiryViaDiskStoreExpiryThread() throws Exception {
    final DiskStore diskStore = getDiskStore(new CacheStoreHelper((Cache) cache).getStore());
    // Overflow 10 elements to disk store
    for (int i = 0; i < 20; i++) {
      Element element = new Element(Integer.toString(i), new Date());
      element.setTimeToIdle(2);
      diskStore.put(element);
    }

    DiskStoreHelper.flushAllEntriesToDisk((Cache) cache).get();
    // Wait for expiry and expiry thread
    RetryAssert.assertBy(
        10,
        TimeUnit.SECONDS,
        new Callable<List<CacheEvent>>() {
          @Override
          public List<CacheEvent> call() throws Exception {
            return getCountingCacheEventListener(cache).getCacheElementsExpired();
          }
        },
        hasSize(20));
  }