public void testUpdatingLastUsed() throws Exception {
    long idle = 600000;
    dc.put("k", "v", -1, -1);
    InternalCacheEntry ice = dc.get("k");
    assert ice.getClass().equals(immortaltype());
    assert ice.getExpiryTime() == -1;
    assert ice.getMaxIdle() == -1;
    assert ice.getLifespan() == -1;
    dc.put("k", "v", -1, idle);
    long oldTime = System.currentTimeMillis();
    Thread.sleep(100); // for time calc granularity
    ice = dc.get("k");
    assert ice.getClass().equals(transienttype());
    assert ice.getExpiryTime() > -1;
    assert ice.getLastUsed() > oldTime;
    Thread.sleep(100); // for time calc granularity
    assert ice.getLastUsed() < System.currentTimeMillis();
    assert ice.getMaxIdle() == idle;
    assert ice.getLifespan() == -1;

    oldTime = System.currentTimeMillis();
    Thread.sleep(100); // for time calc granularity
    assert dc.get("k") != null;

    // check that the last used stamp has been updated on a get
    assert ice.getLastUsed() > oldTime;
    Thread.sleep(100); // for time calc granularity
    assert ice.getLastUsed() < System.currentTimeMillis();
  }
 @Override
 protected String toString(InternalCacheEntry ice) {
   if (ice == null) return null;
   StringBuilder sb = new StringBuilder(256);
   sb.append(ice.getClass().getSimpleName());
   sb.append("[key=").append(ice.getKey()).append(", value=").append(ice.getValue());
   sb.append(", created=").append(ice.getCreated()).append(", isCreated=").append(ice.isCreated());
   sb.append(", lastUsed=")
       .append(ice.getLastUsed())
       .append(", isChanged=")
       .append(ice.isChanged());
   sb.append(", expires=")
       .append(ice.getExpiryTime())
       .append(", isExpired=")
       .append(ice.isExpired(System.currentTimeMillis()));
   sb.append(", canExpire=")
       .append(ice.canExpire())
       .append(", isEvicted=")
       .append(ice.isEvicted());
   sb.append(", isRemoved=").append(ice.isRemoved()).append(", isValid=").append(ice.isValid());
   sb.append(", lifespan=")
       .append(ice.getLifespan())
       .append(", maxIdle=")
       .append(ice.getMaxIdle());
   return sb.append(']').toString();
 }
예제 #3
0
 private void store0(
     InternalCacheEntry entry, Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap)
     throws IOException, UnsupportedKeyTypeException {
   Object key = entry.getKey();
   if (trace) log.tracef("store(\"%s\") ", key);
   String cassandraKey = hashKey(key);
   try {
     addMutation(
         mutationMap,
         ByteBufferUtil.bytes(cassandraKey),
         config.entryColumnFamily,
         ByteBuffer.wrap(entryColumnPath.getColumn()),
         ByteBuffer.wrap(marshall(entry)));
     if (entry.canExpire()) {
       addExpiryEntry(cassandraKey, entry.getExpiryTime(), mutationMap);
     }
   } catch (InterruptedException ie) {
     if (trace) log.trace("Interrupted while trying to marshall entry");
     Thread.currentThread().interrupt();
   }
 }