http://localhost:8080/source/xref/greentea-7.2/net/disk_cache/simple/simple_index_file.cc (M43版本)
// static
index实际上是一个类似于hashmap的数据结构。不幸的是,从这里的反序列化代码来看,其实hashmap的加载并不涉及每个entry的随机load。实际上是顺序load all并就地构造新的hashmap对象。// static void SimpleIndexFile::Deserialize(const char* data, int data_len, base::Time* out_cache_last_modified, SimpleIndexLoadResult* out_result) { DCHECK(data); out_result->Reset(); SimpleIndex::EntrySet* entries = &out_result->entries; Pickle pickle(data, data_len); if (!pickle.data()) { LOG(WARNING) << "Corrupt Simple Index File."; return; } PickleIterator pickle_it(pickle); SimpleIndexFile::PickleHeader* header_p = pickle.headerT<SimpleIndexFile::PickleHeader>(); const uint32 crc_read = header_p->crc; const uint32 crc_calculated = CalculatePickleCRC(pickle); if (crc_read != crc_calculated) { LOG(WARNING) << "Invalid CRC in Simple Index file."; return; } SimpleIndexFile::IndexMetadata index_metadata; if (!index_metadata.Deserialize(&pickle_it)) { LOG(ERROR) << "Invalid index_metadata on Simple Cache Index."; return; } if (!index_metadata.CheckIndexMetadata()) { LOG(ERROR) << "Invalid index_metadata on Simple Cache Index."; return; } #if !defined(OS_WIN) // TODO(gavinp): Consider using std::unordered_map. entries->resize(index_metadata.GetNumberOfEntries() + kExtraSizeForMerge); #endif
嗯,Lucene的文件存储是怎么处理的呢???还有MongoDB呢???
看起来,从这个例子的分析可以看到:一个数据,至少有3种格式:内存存储、序列化/交换格式(stream)、文件存储格式。像这里的disk_cache simple index,以及MongoDB,估计都是把后2者合二为一了。所以它的初始load过程会比较慢。