目标:(二十一)中的问题66
继承关系:
osgEarth::Cache
osgEarth::MemCache
cache中的数据是通过cachebin来实现存放的,cachebin有两种,继承关系为:
osgEarth::CacheBin
MemCacheBin(osgEarth/MemCache.cpp)
在osgEarth::Cache中有维护这osgEarth::CacheBin的map表,osgEarth::CacheBin其实就是最终的缓存数据,具体数据由其成员osg::ref_ptr<osg::Referenced> _metadata来存放。
osgEarth::MemCache中的CacheBin本质上是MemCacheBin,具体数据是在其MemCacheLRU _lru中存放,MemCacheLRU(typedef LRUCache<std::string, MemCacheEntry> MemCacheLRU)是一个osgEarth::LRUCache(Least-recently-used最近最少使用缓存类,很多操作系统中都有此种缓存类),值得注意的是LRUCache中既有map又有list,他们存放的数据是相同的,只所以要这样做,是因为map方便查找和存放,list方便定位较早的元素。
osgEarth/MemCache.cpp
typedef std::pair<osg::ref_ptr<const osg::Object>, Config> MemCacheEntry;
typedef LRUCache<std::string, MemCacheEntry> MemCacheLRU;
struct MemCacheBin : public CacheBin
{
MemCacheLRU _lru;
};
缓存的默认大小为16.
在osgDB::DatabasePager::DatabaseThread::run中处理请求时,会往图层的缓存中写入瓦片信息,在创建瓦片模型时会从缓存中读取缓存信息。
写入缓存过程
osgDB/DatabasePager.cpp
void DatabasePager::DatabaseThread::run()
{
// assume that readNode is thread safe...
ReaderWriter::ReadResult rr = readFromFileCache ?
fileCache->readNode(fileName, dr_loadOptions.get(), false) :
Registry::instance()->readNode(fileName, dr_loadOptions.get(), false);
}
osgEarth/MemCache.cpp
bool write( const std::string& key, const osg::Object* object, const Config& meta, const osgDB::Options* writeOptions)
{
if ( object )
{
osg::ref_ptr<const osg::Object> cloned = osg::clo