diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/extractors/AddressScoreExtractor.cpp b/hoot-core/src/main/cpp/hoot/core/algorithms/extractors/AddressScoreExtractor.cpp
index 8fdb24e..ca13fbc 100644
--- a/hoot-core/src/main/cpp/hoot/core/algorithms/extractors/AddressScoreExtractor.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/algorithms/extractors/AddressScoreExtractor.cpp
@@ -39,7 +39,8 @@ using namespace std;
namespace hoot
{
-QHash<ElementId, QList<Address>> AddressScoreExtractor::_addressesCache;
+QCache<ElementId, QList<Address>> AddressScoreExtractor::_addressesCache(
+ AddressScoreExtractor::CACHE_SIZE_DEFAULT);
int AddressScoreExtractor::_addressCacheHits = 0;
HOOT_FACTORY_REGISTER(FeatureExtractor, AddressScoreExtractor)
@@ -71,6 +72,19 @@ void AddressScoreExtractor::setConfiguration(const Settings& conf)
_addressParser.setPreTranslateTagValuesToEnglish(preTranslateTagValuesToEnglish, conf);
_cacheEnabled = config.getAddressScorerEnableCaching();
+ if (_cacheEnabled)
+ {
+ // Sharing this setting with POI/Poly's max cache sizes for now.
+ const int maxCacheSize = config.getPoiPolygonMaxSizePerCache();
+ if (maxCacheSize > 0)
+ {
+ _addressesCache.setMaxCost(maxCacheSize);
+ }
+ else
+ {
+ _cacheEnabled = false;
+ }
+ }
}
QList<Address> AddressScoreExtractor::_getElementAddresses(
@@ -80,13 +94,12 @@ QList<Address> AddressScoreExtractor::_getElementAddresses(
LOG_TRACE("Collecting addresses from: " << element->getElementId() << "...");
if (_cacheEnabled)
- {
- QHash<ElementId, QList<Address>>::const_iterator itr =
- _addressesCache.find(element->getElementId());
- if (itr != _addressesCache.end())
+ {
+ const QList<Address>* cachedVal = _addressesCache[element->getElementId()];
+ if (cachedVal != 0)
{
_addressCacheHits++;
- return itr.value();
+ return *cachedVal;
}
}
@@ -114,7 +127,7 @@ QList<Address> AddressScoreExtractor::_getElementAddresses(
if (_cacheEnabled)
{
- _addressesCache[element->getElementId()] = elementAddresses;
+ _addressesCache.insert(element->getElementId(), new QList<Address>(elementAddresses));
}
return elementAddresses;