void MemoryCache::remove(CachedResource& resource) { ASSERT(WTF::isMainThread()); LOG(ResourceLoading, "Evicting resource %p for '%s' from cache", &resource, resource.url().string().latin1().data()); // The resource may have already been removed by someone other than our caller, // who needed a fresh copy for a reload. See <http://bugs.webkit.org/show_bug.cgi?id=12479#c6>. if (auto* resources = sessionResourceMap(resource.sessionID())) { #if ENABLE(CACHE_PARTITIONING) auto key = std::make_pair(resource.url(), resource.cachePartition()); #else auto& key = resource.url(); #endif if (resource.inCache()) { // Remove resource from the resource map. resources->remove(key); resource.setInCache(false); // If the resource map is now empty, remove it from m_sessionResources. if (resources->isEmpty()) m_sessionResources.remove(resource.sessionID()); // Remove from the appropriate LRU list. removeFromLRUList(resource); removeFromLiveDecodedResourcesList(resource); adjustSize(resource.hasClients(), -static_cast<int>(resource.size())); } else ASSERT(resources->get(key) != &resource); } resource.deleteIfPossible(); }
void CachedResourceLoader::clearPreloads() { #if PRELOAD_DEBUG printPreloadStats(); #endif if (!m_preloads) return; ListHashSet<CachedResource*>::iterator end = m_preloads->end(); for (ListHashSet<CachedResource*>::iterator it = m_preloads->begin(); it != end; ++it) { CachedResource* res = *it; res->decreasePreloadCount(); bool deleted = res->deleteIfPossible(); if (!deleted && res->preloadResult() == CachedResource::PreloadNotReferenced) memoryCache()->remove(res); } m_preloads.clear(); }