Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::LRUCache< Key, Value, Compare > Class Template Reference

#include <lru-cache.hh>

Public Member Functions

 LRUCache (size_t capacity)
template<typename K>
void upsert (const K &key, const Value &value)
template<typename K>
bool erase (const K &key)
template<typename K>
std::optional< Value > get (const K &key)
template<typename K>
Value * getOrNullptr (const K &key)
size_t size () const noexcept
void clear () noexcept

Detailed Description

template<typename Key, typename Value, typename Compare = std::less<>>
class nix::LRUCache< Key, Value, Compare >

A simple least-recently used cache. Not thread-safe.

Member Function Documentation

◆ get()

template<typename Key, typename Value, typename Compare = std::less<>>
template<typename K>
std::optional< Value > nix::LRUCache< Key, Value, Compare >::get ( const K & key)
inline

Look up an item in the cache. If it exists, it becomes the most recently used item.

Returns
corresponding cache entry, std::nullopt if it's not in the cache

◆ getOrNullptr()

template<typename Key, typename Value, typename Compare = std::less<>>
template<typename K>
Value * nix::LRUCache< Key, Value, Compare >::getOrNullptr ( const K & key)
inline

Look up an item in the cache. If it exists, it becomes the most recently used item.

Returns
mutable pointer to the corresponding cache entry, nullptr if it's not in the cache

◆ upsert()

template<typename Key, typename Value, typename Compare = std::less<>>
template<typename K>
void nix::LRUCache< Key, Value, Compare >::upsert ( const K & key,
const Value & value )
inline

Insert or upsert an item in the cache.

Retire the oldest item.


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