@@ -311,43 +311,47 @@ namespace mtconnect::sink::rest_sink {
311
311
{
312
312
CachedFilePtr file;
313
313
314
- auto cached = m_fileCache.find (name);
315
- if (cached != m_fileCache.end ())
316
314
{
317
- auto fp = cached->second ;
318
- if (!fp->m_cached || fp->m_redirect )
315
+ std::lock_guard<std::recursive_mutex> lock (m_cacheLock);
316
+
317
+ auto cached = m_fileCache.find (name);
318
+ if (cached != m_fileCache.end ())
319
319
{
320
- file = fp;
321
- }
322
- else
323
- {
324
- // Cleanup files if they have changed since last cached
325
- // Also remove any gzipped content as well
326
- auto lastWrite = std::filesystem::last_write_time (fp->m_path );
327
- if (lastWrite == fp->m_lastWrite )
320
+ auto fp = cached->second ;
321
+ if (!fp->m_cached || fp->m_redirect )
322
+ {
328
323
file = fp;
329
- else if (fp->m_pathGz && fs::exists (*fp->m_pathGz ))
330
- fs::remove (*fp->m_pathGz );
324
+ }
325
+ else
326
+ {
327
+ // Cleanup files if they have changed since last cached
328
+ // Also remove any gzipped content as well
329
+ auto lastWrite = std::filesystem::last_write_time (fp->m_path );
330
+ if (lastWrite == fp->m_lastWrite )
331
+ file = fp;
332
+ else if (fp->m_pathGz && fs::exists (*fp->m_pathGz ))
333
+ fs::remove (*fp->m_pathGz );
334
+ }
331
335
}
332
- }
333
-
334
- if (!file)
335
- {
336
- auto path = m_fileMap.find (name);
337
- if (path != m_fileMap.end ())
336
+
337
+ if (!file)
338
338
{
339
- auto ext = path->second .extension ().string ();
340
- auto size = fs::file_size (path->second );
341
- file = make_shared<CachedFile>(path->second , getMimeType (ext),
342
- size <= m_maxCachedFileSize, size);
343
- m_fileCache.insert_or_assign (name, file);
344
- }
345
- else
346
- {
347
- file = findFileInDirectories (name);
339
+ auto path = m_fileMap.find (name);
340
+ if (path != m_fileMap.end ())
341
+ {
342
+ auto ext = path->second .extension ().string ();
343
+ auto size = fs::file_size (path->second );
344
+ file = make_shared<CachedFile>(path->second , getMimeType (ext),
345
+ size <= m_maxCachedFileSize, size);
346
+ m_fileCache.insert_or_assign (name, file);
347
+ }
348
+ else
349
+ {
350
+ file = findFileInDirectories (name);
351
+ }
348
352
}
349
353
}
350
-
354
+
351
355
if (file)
352
356
{
353
357
if (acceptEncoding && acceptEncoding->find (" gzip" ) != string::npos &&
0 commit comments