Repos
C++
859 B31 lines Opens in site
Directory
Raw
Download
#pragma once
// Spec: SPEC.md UX-MD-01. Small LRU of parsed documents keyed by text hash; views are rebuilt every frame.
#include <cstdint>
#include <list>
#include <memory>
#include <string>
#include "ui/MarkdownParser.hpp"
namespace dp::ui {
class MarkdownCache {
public:
static MarkdownCache& instance();
// UI thread. Parses on a miss. The hash selects the entry, the full text confirms it.
std::shared_ptr<const MarkdownDocument> get(const std::string& markdown);
std::size_t size() const { return entries_.size(); }
std::uint64_t parses() const { return parses_; }
void clear() { entries_.clear(); }
private:
struct Entry {
std::uint64_t hash;
std::string text;
std::shared_ptr<const MarkdownDocument> doc;
};
std::list<Entry> entries_; // front = most recent
std::uint64_t parses_ = 0;
};
} // namespace dp::ui