| 194 | } |
| 195 | |
| 196 | ErrorCode Interpreter::updateCacheFile(Session* session, int flag) { |
| 197 | if (mNet->cacheFile.empty()) { |
| 198 | return NOT_SUPPORT; |
| 199 | } |
| 200 | std::lock_guard<std::mutex> _l(mNet->lock); |
| 201 | |
| 202 | // Backend_Auto and no Async work, then don't need updateCache |
| 203 | if (mNet->modes.backendMode == Session_Backend_Auto && !(session->hasAsyncWork())) { |
| 204 | return NO_ERROR; |
| 205 | } |
| 206 | |
| 207 | // Get cache and write to file |
| 208 | auto buffer = session->getCache(); |
| 209 | |
| 210 | // When current cacheSize bigger than previous, update |
| 211 | if (buffer.first != nullptr && buffer.second > mNet->lastCacheSize) { |
| 212 | MNN_PRINT("Update cache to %s, from size:%zu -> size:%zu\n", mNet->cacheFile.c_str(), mNet->lastCacheSize, |
| 213 | buffer.second); |
| 214 | writeCacheFile(mNet, buffer); |
| 215 | mNet->lastCacheSize = buffer.second; |
| 216 | } |
| 217 | // Reset cache |
| 218 | session->loadCache(nullptr, 0); |
| 219 | return NO_ERROR; |
| 220 | } |
| 221 | |
| 222 | Interpreter::Interpreter(Content* net) { |
| 223 | MNN_ASSERT(nullptr != net); |