LLDB  mainline
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
lldb_private::DataFileCache Class Reference

This class enables data to be cached into a directory using the llvm caching code. More...

#include <DataFileCache.h>

Collaboration diagram for lldb_private::DataFileCache:
Collaboration graph
[legend]

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. More...
 
std::unique_ptr< llvm::MemoryBuffer > GetCachedData (llvm::StringRef key)
 Get cached data from the cache directory for the specified key. More...
 
bool SetCachedData (llvm::StringRef key, llvm::ArrayRef< uint8_t > data)
 Set cached data for the specified key. More...
 
Status RemoveCacheFile (llvm::StringRef key)
 Remove the cache file associated with the key. More...
 

Static Public Member Functions

static llvm::CachePruningPolicy GetLLDBIndexCachePolicy ()
 Gets the default LLDB index cache policy, which is controlled by the "LLDBIndexCache" family of settings. More...
 

Private Member Functions

FileSpec GetCacheFilePath (llvm::StringRef key)
 Return the cache file that is associated with the key. More...
 

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
 

Detailed Description

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 44 of file DataFileCache.h.

Constructor & Destructor Documentation

◆ DataFileCache()

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().

Member Function Documentation

◆ GetCachedData()

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.

Parameters
keyThe unique string key that identifies data being cached.
Returns
A valid unique pointer to a memory buffer if the data is available, or a unique pointer that contains NULL if the data is not available.

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::ManualDWARFIndex::LoadFromCache(), and lldb_private::Symtab::LoadFromCache().

◆ GetCacheFilePath()

FileSpec DataFileCache::GetCacheFilePath ( llvm::StringRef  key)
private

Return the cache file that is associated with the key.

Definition at line 150 of file DataFileCache.cpp.

References lldb_private::FileSpec::AppendPathComponent(), m_cache_dir, and string().

Referenced by RemoveCacheFile().

◆ GetLLDBIndexCachePolicy()

llvm::CachePruningPolicy DataFileCache::GetLLDBIndexCachePolicy ( )
static

◆ RemoveCacheFile()

Status DataFileCache::RemoveCacheFile ( llvm::StringRef  key)

◆ SetCachedData()

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.

Parameters
keyThe unique string key that identifies data being cached.
Returns
True if the data was successfully cached, false otherwise.

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::ManualDWARFIndex::SaveToCache(), and lldb_private::Symtab::SaveToCache().

Member Data Documentation

◆ m_cache_callback

llvm::FileCache lldb_private::DataFileCache::m_cache_callback
private

Definition at line 92 of file DataFileCache.h.

Referenced by DataFileCache(), GetCachedData(), and SetCachedData().

◆ m_cache_dir

FileSpec lldb_private::DataFileCache::m_cache_dir
private

Definition at line 93 of file DataFileCache.h.

Referenced by DataFileCache(), and GetCacheFilePath().

◆ m_mem_buff_up

std::unique_ptr<llvm::MemoryBuffer> lldb_private::DataFileCache::m_mem_buff_up
private

Definition at line 95 of file DataFileCache.h.

Referenced by DataFileCache(), and GetCachedData().

◆ m_mutex

std::mutex lldb_private::DataFileCache::m_mutex
private

Definition at line 94 of file DataFileCache.h.

Referenced by GetCachedData(), and SetCachedData().

◆ m_take_ownership

bool lldb_private::DataFileCache::m_take_ownership = false
private

Definition at line 96 of file DataFileCache.h.

Referenced by DataFileCache(), and GetCachedData().


The documentation for this class was generated from the following files: