llvm/lldb/include/lldb/Core/DataFileCache.h

//===-- DataFileCache.h -----------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_CORE_DATAFILECACHE_H
#define LLDB_CORE_DATAFILECACHE_H

#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/UUID.h"
#include "lldb/lldb-forward.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/CachePruning.h"
#include "llvm/Support/Caching.h"
#include "llvm/Support/MemoryBuffer.h"

#include <mutex>
#include <optional>

namespace lldb_private {

/// 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', '\n' };
///     cache.SetCachedData(key, data);
///   }

class DataFileCache {};

/// A signature for a given file on disk.
///
/// Any files that are cached in the LLDB index cached need some data that
/// uniquely identifies a file on disk and this information should be written
/// into each cache file so we can validate if the cache file still matches
/// the file we are trying to load cached data for. Objects can fill out this
/// signature and then encode and decode them to validate the signatures
/// match. If they do not match, the cache file on disk should be removed as
/// it is out of date.
struct CacheSignature {};

/// Many cache files require string tables to store data efficiently. This
/// class helps create string tables.
class ConstStringTable {};

/// Many cache files require string tables to store data efficiently. This
/// class helps give out strings from a string table that was read from a
/// cache file.
class StringTableReader {};

} // namespace lldb_private

#endif // LLDB_CORE_DATAFILECACHE_H