@Override
    @SuppressWarnings({ "rawtypes" })
    synchronized public Value put(Transaction tx, Key key, Value value) throws IOException {

        Value oldValue = null;

        if (lastGetNodeCache != null && tx.equals(lastCacheTxSrc.get())) {

            if(lastGetEntryCache.getKey().equals(key)) {
                oldValue = lastGetEntryCache.setValue(value);
                lastGetEntryCache.setValue(value);
                lastGetNodeCache.storeUpdate(tx);
                flushCache();
                return oldValue;
            }

            // This searches from the last location of a call to get for the element to replace
            // all the way to the end of the ListIndex.
            Iterator<Map.Entry<Key, Value>> iterator = lastGetNodeCache.iterator(tx);
            while (iterator.hasNext()) {
                Map.Entry<Key, Value> entry = iterator.next();
                if (entry.getKey().equals(key)) {
                    oldValue = entry.setValue(value);
                    ((ListIterator) iterator).getCurrent().storeUpdate(tx);
                    flushCache();
                    return oldValue;
                }
            }
        } else {
            flushCache();
        }

        // Not found because the cache wasn't set or its not at the end of the list so we
        // start from the beginning and go to the cached location or the end, then we do
        // an add if its not found.
        Iterator<Map.Entry<Key, Value>> iterator = iterator(tx);
        while (iterator.hasNext() && ((ListIterator) iterator).getCurrent() != lastGetNodeCache) {
            Map.Entry<Key, Value> entry = iterator.next();
            if (entry.getKey().equals(key)) {
                oldValue = entry.setValue(value);
                ((ListIterator) iterator).getCurrent().storeUpdate(tx);
                flushCache();
                return oldValue;
            }
        }

        // Not found so add it last.
        flushCache();

        return add(tx, key, value);
    }
@Test(timeout=60000)
    public void testPut() throws Exception {
        createPageFileAndIndex(100);

        ListIndex<String, Long> listIndex = ((ListIndex<String, Long>) this.index);
        this.index.load(tx);
        tx.commit();

        int count = 30;
        tx = pf.tx();
        doInsert(count);
        tx.commit();
        assertEquals("correct size", count, listIndex.size());

        tx = pf.tx();
        Long value = listIndex.get(tx, key(10));
        assertNotNull(value);
        listIndex.put(tx, key(10), 1024L);
        tx.commit();

        tx = pf.tx();
        value = listIndex.get(tx, key(10));
        assertEquals(1024L, value.longValue());
        assertTrue(listIndex.size() == 30);
        tx.commit();

        tx = pf.tx();
        value = listIndex.put(tx, key(31), 2048L);
        assertNull(value);
        assertTrue(listIndex.size() == 31);
        tx.commit();
    }