|
19 | 19 |
|
20 | 20 | using namespace lldb_private;
|
21 | 21 |
|
22 |
| -DataFileCache::DataFileCache(llvm::StringRef path) { |
23 |
| - m_cache_dir.SetPath(path); |
24 | 22 |
|
25 |
| - // Prune the cache based off of the LLDB settings each time we create a cache |
26 |
| - // object. |
27 |
| - ModuleListProperties &properties = |
28 |
| - ModuleList::GetGlobalModuleListProperties(); |
29 |
| - llvm::CachePruningPolicy policy; |
30 |
| - // Only scan once an hour. If we have lots of debug sessions we don't want |
31 |
| - // to scan this directory too often. A timestamp file is written to the |
32 |
| - // directory to ensure different processes don't scan the directory too often. |
33 |
| - // This setting doesn't mean that a thread will continually scan the cache |
34 |
| - // directory within this process. |
35 |
| - policy.Interval = std::chrono::hours(1); |
36 |
| - // Get the user settings for pruning. |
37 |
| - policy.MaxSizeBytes = properties.GetLLDBIndexCacheMaxByteSize(); |
38 |
| - policy.MaxSizePercentageOfAvailableSpace = |
39 |
| - properties.GetLLDBIndexCacheMaxPercent(); |
40 |
| - policy.Expiration = |
41 |
| - std::chrono::hours(properties.GetLLDBIndexCacheExpirationDays() * 24); |
| 23 | +llvm::CachePruningPolicy DataFileCache::GetLLDBIndexCachePolicy() { |
| 24 | + static llvm::CachePruningPolicy policy; |
| 25 | + static llvm::once_flag once_flag; |
| 26 | + |
| 27 | + llvm::call_once(once_flag, []() { |
| 28 | + // Prune the cache based off of the LLDB settings each time we create a |
| 29 | + // cache object. |
| 30 | + ModuleListProperties &properties = |
| 31 | + ModuleList::GetGlobalModuleListProperties(); |
| 32 | + // Only scan once an hour. If we have lots of debug sessions we don't want |
| 33 | + // to scan this directory too often. A timestamp file is written to the |
| 34 | + // directory to ensure different processes don't scan the directory too |
| 35 | + // often. This setting doesn't mean that a thread will continually scan the |
| 36 | + // cache directory within this process. |
| 37 | + policy.Interval = std::chrono::hours(1); |
| 38 | + // Get the user settings for pruning. |
| 39 | + policy.MaxSizeBytes = properties.GetLLDBIndexCacheMaxByteSize(); |
| 40 | + policy.MaxSizePercentageOfAvailableSpace = |
| 41 | + properties.GetLLDBIndexCacheMaxPercent(); |
| 42 | + policy.Expiration = |
| 43 | + std::chrono::hours(properties.GetLLDBIndexCacheExpirationDays() * 24); |
| 44 | + }); |
| 45 | + return policy; |
| 46 | +} |
| 47 | + |
| 48 | +DataFileCache::DataFileCache(llvm::StringRef path, llvm::CachePruningPolicy policy) { |
| 49 | + m_cache_dir.SetPath(path); |
42 | 50 | pruneCache(path, policy);
|
43 | 51 |
|
44 | 52 | // This lambda will get called when the data is gotten from the cache and
|
@@ -311,3 +319,4 @@ llvm::StringRef StringTableReader::Get(uint32_t offset) const {
|
311 | 319 | return llvm::StringRef();
|
312 | 320 | return llvm::StringRef(m_data.data() + offset);
|
313 | 321 | }
|
| 322 | + |
0 commit comments