| 2046 | |
| 2047 | // Clears the cache, saving the entries to second cache, then waits for each item to be evictable and evicts it. |
| 2048 | ACTOR static Future<Void> clear_impl(ObjectCache* self, bool waitForSafeEviction) { |
| 2049 | // Claim ownership of all of our cached items, removing them from the evictor's control and quota. |
| 2050 | for (auto& ie : self->cache) { |
| 2051 | self->pEvictor->reclaim(ie.second); |
| 2052 | } |
| 2053 | |
| 2054 | // All items are in the cache so we don't need the prioritized eviction order anymore, and the cache is about |
| 2055 | // to be destroyed so the prioritizedEvictions head/tail will become invalid. |
| 2056 | self->prioritizedEvictions.clear(); |
| 2057 | |
| 2058 | state typename CacheT::iterator i = self->cache.begin(); |
| 2059 | while (i != self->cache.end()) { |
| 2060 | wait(waitForSafeEviction ? i->second.item.onEvictable() : i->second.item.cancel()); |
| 2061 | ++i; |
| 2062 | } |
| 2063 | self->cache.clear(); |
| 2064 | |
| 2065 | return Void(); |
| 2066 | } |
| 2067 | |
| 2068 | Future<Void> clear(bool waitForSafeEviction = false) { return clear_impl(this, waitForSafeEviction); } |
| 2069 | |