#ifndef CLIO_SIMPLECACHE_H_INCLUDED #define CLIO_SIMPLECACHE_H_INCLUDED #include #include #include #include #include #include #include #include namespace Backend { class SimpleCache { struct CacheEntry { uint32_t seq = 0; Blob blob; }; std::map map_; mutable std::shared_mutex mtx_; uint32_t latestSeq_ = 0; std::atomic_bool full_ = false; // temporary set to prevent background thread from writing already deleted // data. not used when cache is full std::unordered_set> deletes_; public: // Update the cache with new ledger objects // set isBackground to true when writing old data from a background thread void update( std::vector const& blobs, uint32_t seq, bool isBackground = false); std::optional get(ripple::uint256 const& key, uint32_t seq) const; // always returns empty optional if isFull() is false std::optional getSuccessor(ripple::uint256 const& key, uint32_t seq) const; // always returns empty optional if isFull() is false std::optional getPredecessor(ripple::uint256 const& key, uint32_t seq) const; void setFull(); // whether the cache has all data for the most recent ledger bool isFull(); size_t size(); }; } // namespace Backend #endif