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 MemoryCache::insertInLRUList(CachedResource& resource) { ASSERT(resource.inCache()); ASSERT(resource.accessCount() > 0); auto addResult = lruListFor(resource).add(&resource); ASSERT_UNUSED(addResult, addResult.isNewEntry); }
void DocLoader::clearPreloads() { #if PRELOAD_DEBUG printPreloadStats(); #endif ListHashSet<CachedResource*>::iterator end = m_preloads.end(); for (ListHashSet<CachedResource*>::iterator it = m_preloads.begin(); it != end; ++it) { CachedResource* res = *it; res->decreasePreloadCount(); if (res->canDelete() && !res->inCache()) delete res; else if (res->preloadResult() == CachedResource::PreloadNotReferenced) cache()->remove(res); } m_preloads.clear(); }
void MemoryCache::resourceAccessed(CachedResource& resource) { ASSERT(resource.inCache()); // Need to make sure to remove before we increase the access count, since // the queue will possibly change. removeFromLRUList(resource); // If this is the first time the resource has been accessed, adjust the size of the cache to account for its initial size. if (!resource.accessCount()) adjustSize(resource.hasClients(), resource.size()); // Add to our access count. resource.increaseAccessCount(); // Now insert into the new queue. insertInLRUList(resource); }
void MemoryCache::revalidationSucceeded(CachedResource* revalidatingResource, const ResourceResponse& response) { CachedResource* resource = revalidatingResource->resourceToRevalidate(); ASSERT(resource); ASSERT(!resource->inCache()); ASSERT(resource->isLoaded()); ASSERT(revalidatingResource->inCache()); // Calling evict() can potentially delete revalidatingResource, which we use // below. This mustn't be the case since revalidation means it is loaded // and so canDelete() is false. ASSERT(!revalidatingResource->canDelete()); evict(revalidatingResource); CachedResourceMap& resources = getSessionMap(resource->sessionID()); #if ENABLE(CACHE_PARTITIONING) ASSERT(!resources.get(resource->url()) || !resources.get(resource->url())->get(resource->cachePartition())); CachedResourceItem* originMap = resources.get(resource->url()); if (!originMap) { originMap = new CachedResourceItem; resources.set(resource->url(), adoptPtr(originMap)); } originMap->set(resource->cachePartition(), resource); #else ASSERT(!resources.get(resource->url())); resources.set(resource->url(), resource); #endif resource->setInCache(true); resource->updateResponseAfterRevalidation(response); insertInLRUList(resource); int delta = resource->size(); if (resource->decodedSize() && resource->hasClients()) insertInLiveDecodedResourcesList(resource); if (delta) adjustSize(resource->hasClients(), delta); revalidatingResource->switchClientsToRevalidatedResource(); ASSERT(!revalidatingResource->m_deleted); // this deletes the revalidating resource revalidatingResource->clearResourceToRevalidate(); }