private void doWrite(String tag, Object o, WriteHandler w, boolean cache) throws IOException {
        if (cache) {
            if (shouldSkipCache(o))
                doWrite(tag, o, w, false);
            else {
                int index = getPriorityCache().oldIndex(o);
                if (index == -1) {
                    writeCode(Codes.PUT_PRIORITY_CACHE);
                    doWrite(tag, o, w, false);
                } else {
                    if (index < Ranges.PRIORITY_CACHE_PACKED_END) {
                        writeCode((int) Codes.PRIORITY_CACHE_PACKED_START + index);
                    } else {
                        writeCode(Codes.GET_PRIORITY_CACHE);
                        writeInt(index);
                    }
                }
            }
        } else {
            w.write(this, o);
        }
    }