LevelDBCacheImpl::LevelDBCacheImpl( const CacheOptions& options ) : osgEarth::Cache( options ), _options ( options ), _active ( true ) { // Force OSG to initialize the image wrapper. Failure to do this can result // in a race condition within OSG when the cache is accessed from multiple threads. osgDB::ObjectWrapperManager* owm = osgDB::Registry::instance()->getObjectWrapperManager(); owm->findWrapper("osg::Image"); owm->findWrapper("osg::HeightField"); if ( _options.rootPath().isSet() ) { _rootPath = URI( *_options.rootPath(), options.referrer() ).full(); } else { // read the root path from ENV is necessary: const char* cachePath = ::getenv(OSGEARTH_ENV_CACHE_PATH); if ( cachePath ) { _rootPath = cachePath; OE_INFO << LC << "Cache location set from environment: \"" << cachePath << "\"" << std::endl; } } const char* maxsize = ::getenv(OSGEARTH_ENV_CACHE_MAX_SIZE_MB); if ( maxsize ) { unsigned mb = as<unsigned>(std::string(maxsize), 0u); if ( mb > 0 ) { _options.maxSizeMB() = mb; OE_INFO << LC << "Set max cache size from environment: " << (_options.maxSizeMB().value()) << " MB" << std::endl; } else { OE_WARN << LC << "Env var \"" OSGEARTH_ENV_CACHE_MAX_SIZE_MB "\" set to an invalid value" << std::endl; } } _tracker = new Tracker(_options, _rootPath); if ( !_rootPath.empty() ) { init(); } else { _active = false; OE_WARN << LC << "Illegal: no root path set for cache!" << std::endl; } }
LevelDBCacheImpl::LevelDBCacheImpl( const CacheOptions& options ) : osgEarth::Cache( options ), _options ( options ), _active ( true ) { if ( _options.rootPath().isSet() ) { _rootPath = URI( *_options.rootPath(), options.referrer() ).full(); } else { // read the root path from ENV is necessary: const char* cachePath = ::getenv(OSGEARTH_ENV_CACHE_PATH); if ( cachePath ) { _rootPath = cachePath; OE_INFO << LC << "Cache location set from environment: \"" << cachePath << "\"" << std::endl; } } const char* maxsize = ::getenv(OSGEARTH_ENV_CACHE_MAX_SIZE_MB); if ( maxsize ) { unsigned mb = as<unsigned>(std::string(maxsize), 0u); if ( mb > 0 ) { _options.maxSizeMB() = mb; OE_INFO << LC << "Set max cache size from environment: " << (_options.maxSizeMB().value()) << " MB" << std::endl; } else { OE_WARN << LC << "Env var \"" OSGEARTH_ENV_CACHE_MAX_SIZE_MB "\" set to an invalid value" << std::endl; } } _tracker = new Tracker(_options, _rootPath); if ( !_rootPath.empty() ) { init(); } else { _active = false; OE_WARN << LC << "Illegal: no root path set for cache!" << std::endl; } }