LLDB mainline
|
This class enables data to be cached into a directory using the llvm caching code. More...
#include <DataFileCache.h>
Public Member Functions | |
DataFileCache (llvm::StringRef path, llvm::CachePruningPolicy policy=DataFileCache::GetLLDBIndexCachePolicy()) | |
Create a data file cache in the directory path that is specified, using the specified policy. | |
std::unique_ptr< llvm::MemoryBuffer > | GetCachedData (llvm::StringRef key) |
Get cached data from the cache directory for the specified key. | |
bool | SetCachedData (llvm::StringRef key, llvm::ArrayRef< uint8_t > data) |
Set cached data for the specified key. | |
Status | RemoveCacheFile (llvm::StringRef key) |
Remove the cache file associated with the key. | |
Static Public Member Functions | |
static llvm::CachePruningPolicy | GetLLDBIndexCachePolicy () |
Gets the default LLDB index cache policy, which is controlled by the "LLDBIndexCache" family of settings. | |
Private Member Functions | |
FileSpec | GetCacheFilePath (llvm::StringRef key) |
Return the cache file that is associated with the key. | |
Private Attributes | |
llvm::FileCache | m_cache_callback |
FileSpec | m_cache_dir |
std::mutex | m_mutex |
std::unique_ptr< llvm::MemoryBuffer > | m_mem_buff_up |
bool | m_take_ownership = false |
This class enables data to be cached into a directory using the llvm caching code.
Data can be stored and accessed using a unique string key. The data will be stored in the directory that is specified in the DataFileCache constructor. The data will be stored in files that start with "llvmcache-<key>" where <key> is the key name specified when getting to setting cached data.
Sample code for how to use the cache:
DataFileCache cache("/tmp/lldb-test-cache"); StringRef key("Key1"); auto mem_buffer_up = cache.GetCachedData(key); if (mem_buffer_up) { printf("cached data:\n%s", mem_buffer_up->getBufferStart()); } else { std::vector<uint8_t> data = { 'h', 'e', 'l', 'l', 'o', '
' }; cache.SetCachedData(key, data); }
Definition at line 45 of file DataFileCache.h.
DataFileCache::DataFileCache | ( | llvm::StringRef | path, |
llvm::CachePruningPolicy | policy = DataFileCache::GetLLDBIndexCachePolicy() |
||
) |
Create a data file cache in the directory path that is specified, using the specified policy.
Data will be cached in files created in this directory when clients call DataFileCache::SetCacheData.
Definition at line 47 of file DataFileCache.cpp.
References lldb_private::GetLog(), LLDB_LOG_ERROR, m_cache_callback, m_cache_dir, m_mem_buff_up, m_take_ownership, lldb_private::Modules, and lldb_private::FileSpec::SetPath().
std::unique_ptr< llvm::MemoryBuffer > DataFileCache::GetCachedData | ( | llvm::StringRef | key | ) |
Get cached data from the cache directory for the specified key.
Keys must be unique for any given data. This function attempts to see if the data is available for the specified key and will return a valid memory buffer is data is available.
key | The unique string key that identifies data being cached. |
Definition at line 74 of file DataFileCache.cpp.
References lldb_private::GetLog(), LLDB_LOG_ERROR, m_cache_callback, m_mem_buff_up, m_mutex, m_take_ownership, and lldb_private::Modules.
Referenced by lldb_private::Symtab::LoadFromCache(), and lldb_private::plugin::dwarf::ManualDWARFIndex::LoadFromCache().
|
private |
Return the cache file that is associated with the key.
Definition at line 150 of file DataFileCache.cpp.
References lldb_private::FileSpec::AppendPathComponent(), and m_cache_dir.
Referenced by RemoveCacheFile().
|
static |
Gets the default LLDB index cache policy, which is controlled by the "LLDBIndexCache" family of settings.
Definition at line 22 of file DataFileCache.cpp.
References lldb_private::ModuleList::GetGlobalModuleListProperties(), lldb_private::ModuleListProperties::GetLLDBIndexCacheExpirationDays(), lldb_private::ModuleListProperties::GetLLDBIndexCacheMaxByteSize(), and lldb_private::ModuleListProperties::GetLLDBIndexCacheMaxPercent().
Status DataFileCache::RemoveCacheFile | ( | llvm::StringRef | key | ) |
Remove the cache file associated with the key.
Definition at line 158 of file DataFileCache.cpp.
References lldb_private::FileSystem::Exists(), GetCacheFilePath(), lldb_private::FileSystem::Instance(), and lldb_private::FileSystem::RemoveFile().
Referenced by lldb_private::Symtab::LoadFromCache(), and lldb_private::plugin::dwarf::ManualDWARFIndex::LoadFromCache().
bool DataFileCache::SetCachedData | ( | llvm::StringRef | key, |
llvm::ArrayRef< uint8_t > | data | ||
) |
Set cached data for the specified key.
Setting the cached data will save a file in the cache directory to contain the specified data.
key | The unique string key that identifies data being cached. |
Definition at line 108 of file DataFileCache.cpp.
References lldb_private::GetLog(), LLDB_LOG_ERROR, m_cache_callback, m_mutex, and lldb_private::Modules.
Referenced by lldb_private::Symtab::SaveToCache(), and lldb_private::plugin::dwarf::ManualDWARFIndex::SaveToCache().
|
private |
Definition at line 93 of file DataFileCache.h.
Referenced by DataFileCache(), GetCachedData(), and SetCachedData().
|
private |
Definition at line 94 of file DataFileCache.h.
Referenced by DataFileCache(), and GetCacheFilePath().
|
private |
Definition at line 96 of file DataFileCache.h.
Referenced by DataFileCache(), and GetCachedData().
|
private |
Definition at line 95 of file DataFileCache.h.
Referenced by GetCachedData(), and SetCachedData().
|
private |
Definition at line 97 of file DataFileCache.h.
Referenced by DataFileCache(), and GetCachedData().