HostInfoCache: Simplify cost handling.

This commit is contained in:
Nodir Temirkhodjaev 2019-04-15 13:54:13 +05:00
parent 122f1323ae
commit 10267541b7

View File

@ -5,7 +5,7 @@
HostInfoCache::HostInfoCache(QObject *parent) : HostInfoCache::HostInfoCache(QObject *parent) :
QObject(parent), QObject(parent),
m_manager(new HostInfoManager(this)), m_manager(new HostInfoManager(this)),
m_cache(1 * 1024 * 1024) m_cache(1000)
{ {
connect(m_manager, &HostInfoManager::lookupFinished, connect(m_manager, &HostInfoManager::lookupFinished,
this, &HostInfoCache::handleFinishedLookup); this, &HostInfoCache::handleFinishedLookup);
@ -24,7 +24,7 @@ QString HostInfoCache::hostName(const QString &address)
if (hostInfo == nullptr) { if (hostInfo == nullptr) {
hostInfo = new HostInfo(); hostInfo = new HostInfo();
m_cache.insert(address, hostInfo, 4); m_cache.insert(address, hostInfo, 1);
m_manager->lookupHost(address); m_manager->lookupHost(address);
} }
@ -42,12 +42,11 @@ void HostInfoCache::clear()
void HostInfoCache::handleFinishedLookup(const QString &address, void HostInfoCache::handleFinishedLookup(const QString &address,
const QString &hostName) const QString &hostName)
{ {
HostInfo *hostInfo = m_cache.take(address); HostInfo *hostInfo = m_cache.object(address);
if (hostInfo == nullptr) if (hostInfo == nullptr)
return; return;
hostInfo->hostName = hostName; hostInfo->hostName = hostName;
m_cache.insert(address, hostInfo, hostName.size());
emitCacheChanged(); emitCacheChanged();
} }