Exemplo n.º 1
0
 /** {@inheritDoc} */
 public Object getOnce(Object key, Object aux) throws IOException {
   if (key == null) throw new IllegalArgumentException();
   final ByteBuffer buf;
   synchronized (this) {
     buf = m_lruMap.remove(key);
   }
   if (buf != null) {
     final CacheObjectBroker broker = m_cache.getCacheObjectBroker();
     buf.position(0);
     return broker.decodeFromByteBuffer(buf, aux);
   }
   return m_cache.readFromStore(key, aux);
 }
Exemplo n.º 2
0
 /** {@inheritDoc} */
 public void put(Object key, Object obj) {
   if (key == null || obj == null) throw new IllegalArgumentException();
   final CacheObjectBroker broker = m_cache.getCacheObjectBroker();
   final int objSize = broker.getEncodedSizeOf(obj);
   while (true) {
     final ByteBuffer buf;
     try {
       buf = m_bufAlloc.allocByteBuffer(objSize);
     } catch (OutOfMemoryError e) {
       if (spillOneObject()) continue;
       throw e;
     }
     broker.encodeToByteBuffer(buf, obj);
     synchronized (this) {
       m_lruMap.put(key, buf);
       m_curSize += objSize;
     }
     break;
   }
 }