Cache::ApplyResult Cache::applyPolicy( CachePolicy& cachePolicy ) const { ReadLock readLock( mutex_, boost::try_to_lock ); if( !readLock.owns_lock() ) return AR_CACHEBUSY; if( cacheMap_.empty() || !cachePolicy.willPolicyBeActivated( *this ) ) return AR_NOTACTIVATED; std::vector< CacheObject* > cacheObjectList; cacheObjectList.reserve( cacheMap_.size() ); for( CacheMap::const_iterator it = cacheMap_.begin(); it != cacheMap_.end(); ++it ) { CacheObject* object = it->second.get(); if( object && object->isValid() && object->isLoaded_() ) { cacheObjectList.push_back( object ); } } if( cacheObjectList.empty() ) return AR_EMPTY; std::vector< CacheObject * > modifiedList; cachePolicy.apply_( *this, cacheObjectList, modifiedList ); unloadCacheObjectsWithPolicy_( cachePolicy, modifiedList ); return AR_ACTIVATED; }
void TerrainLayer::refreshTileSourceCachePolicyHint() { if ( _tileSource.valid() && !_initOptions.cachePolicy().isSet() ) { CachePolicy hint = _tileSource->getCachePolicyHint( _targetProfileHint.get() ); if ( hint.usage().isSetTo(CachePolicy::USAGE_NO_CACHE) ) { setCachePolicy( hint ); OE_INFO << LC << "Caching disabled (by policy hint)" << std::endl; } } }
void TerrainLayer::refreshTileSourceCachePolicyHint(TileSource* ts) { if ( ts && getCacheSettings() && !options().cachePolicy().isSet() ) { CachePolicy hint = ts->getCachePolicyHint( _targetProfileHint.get() ); if ( hint.usage().isSetTo(CachePolicy::USAGE_NO_CACHE) ) { getCacheSettings()->cachePolicy() = hint; OE_INFO << LC << "Caching disabled (by policy hint)" << std::endl; } } }
TileSource* TerrainLayer::getTileSource() const { if ( _tileSourceInitFailed ) return 0L; if ((_tileSource.valid() && !_tileSourceInitAttempted) || (!_tileSource.valid() && !isCacheOnly())) { Threading::ScopedMutexLock lock(_initTileSourceMutex); // double-check pattern if ((_tileSource.valid() && !_tileSourceInitAttempted) || (!_tileSource.valid() && !isCacheOnly())) { // Initialize the tile source once. const_cast<TerrainLayer*>(this)->initTileSource(); // read the cache policy hint from the tile source unless user expressly set // a policy in the initialization options. if ( _tileSource.valid() && !_initOptions.cachePolicy().isSet() ) { CachePolicy hint = _tileSource->getCachePolicyHint( _targetProfileHint.get() ); if ( hint.usage().isSetTo(CachePolicy::USAGE_NO_CACHE) ) { const_cast<TerrainLayer*>(this)->setCachePolicy( hint ); OE_INFO << LC << "Caching disabled (by policy hint)" << std::endl; } } // Unless the user has already configured an expiration policy, use the "last modified" // timestamp of the TileSource to set a minimum valid cache entry timestamp. if ( _tileSource.valid() ) { CachePolicy& cp = _runtimeOptions->cachePolicy().mutable_value(); if ( !cp.minTime().isSet() && !cp.maxAge().isSet() ) { cp.minTime() = _tileSource->getLastModifiedTime(); } OE_INFO << LC << "cache policy = " << getCachePolicy().usageString() << std::endl; } } } return _tileSource.get(); }
void Cache::unloadCacheObjectsWithPolicy_( CachePolicy& cachePolicy, const std::vector< CacheObject * >& cacheObjectList ) const { for( std::vector< CacheObject *>::const_iterator it = cacheObjectList.begin(); it != cacheObjectList.end(); ++it ) { ( *it )->cacheUnload( ); if( cachePolicy.isPolicySatisfied( *this ) ) return; } }
TileSource* TerrainLayer::getTileSource() const { if ( _tileSourceInitFailed ) return 0L; if ((_tileSource.valid() && !_tileSourceInitAttempted) || (!_tileSource.valid() && !isCacheOnly())) { OpenThreads::ScopedLock< OpenThreads::Mutex > lock(const_cast<TerrainLayer*>(this)->_initTileSourceMutex ); // double-check pattern if ((_tileSource.valid() && !_tileSourceInitAttempted) || (!_tileSource.valid() && !isCacheOnly())) { // Initialize the tile source once. const_cast<TerrainLayer*>(this)->initTileSource(); // read the cache policy hint from the tile source unless user expressly set // a policy in the initialization options. if ( _tileSource.valid() && !_initOptions.cachePolicy().isSet() ) { CachePolicy hint = _tileSource->getCachePolicyHint(); if ( hint.usage().isSetTo(CachePolicy::USAGE_NO_CACHE) ) { const_cast<TerrainLayer*>(this)->setCachePolicy( hint ); OE_INFO << LC << "Caching disabled (by policy hint)" << std::endl; } } OE_INFO << LC << "cache policy = " << getCachePolicy().usageString() << std::endl; } } return _tileSource.get(); }
void CachePolicy::mergeAndOverride(const CachePolicy& rhs) { if ( rhs.usage().isSet() ) usage() = rhs.usage().get(); if ( rhs.minTime().isSet() ) minTime() = rhs.minTime().get(); if ( rhs.maxAge().isSet() ) maxAge() = rhs.maxAge().get(); }