All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.ehcache.NonEternalElementData Maven / Gradle / Ivy

Go to download

Ehcache is an open source, standards-based cache used to boost performance, offload the database and simplify scalability. Ehcache is robust, proven and full-featured and this has made it the most widely-used Java-based cache.

There is a newer version: 2.10.9.2
Show newest version
/*
 * All content copyright Terracotta, Inc., unless otherwise indicated. All rights reserved.
 */
package net.sf.ehcache;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

/**
 * Serialized representation of non-eternal {@link Element}
 */
public class NonEternalElementData extends ElementData {
  private volatile int     timeToLive;
  private volatile int     timeToIdle;

  public NonEternalElementData() {
    // for serialization
  }

  public NonEternalElementData(final Element element) {
    super(element);
    timeToIdle = element.getTimeToIdle();
    timeToLive = element.getTimeToLive();
  }

  @Override
  public Element createElement(final Object key) {
    Element element = new Element(key, value, version, creationTime, lastAccessTime, hitCount, cacheDefaultLifespan,
                                  timeToLive, timeToIdle, lastUpdateTime);
    return element;
  }

  @Override
  protected void writeAttributes(ObjectOutput oos) throws IOException {
    oos.writeInt(timeToLive);
    oos.writeInt(timeToIdle);
  }

  @Override
  protected void readAttributes(ObjectInput in) throws IOException {
    timeToLive = in.readInt();
    timeToIdle = in.readInt();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy