Volume Cartographer 2.27.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
volcart::Cache< TKey, TValue > Class Template Referenceabstract

Abstract Base Class for Key-Value Caches. More...

#include <vc/core/types/Cache.hpp>

Inheritance diagram for volcart::Cache< TKey, TValue >:
[legend]

Public Types

using Pointer = std::shared_ptr< Cache >
 

Public Member Functions

virtual ~Cache ()=default
 
virtual void setCapacity (std::size_t newCapacity)=0
 Set the maximum number of elements in the cache. More...
 
virtual auto capacity () const -> std::size_t=0
 Get the maximum number of elements in the cache. More...
 
virtual auto size () const -> std::size_t=0
 Get the current number of elements in the cache. More...
 
virtual auto get (const TKey &k) -> TValue=0
 Get an item from the cache by key. More...
 
virtual auto put (const TKey &k, const TValue &v) -> void=0
 Put an item into the cache. More...
 
virtual auto contains (const TKey &k) -> bool=0
 Check if an item is already in the cache. More...
 
virtual void onEvict (std::function< bool(TKey &, TValue &)> fn)=0
 Callback function when items are evicted. More...
 
virtual void resetOnEvict ()=0
 Remove the validation callback function. More...
 
virtual auto evict () -> void=0
 Evict items following the cache policy. More...
 
virtual auto purge () -> void=0
 Evict all items ignoring cache policy. More...
 

Protected Member Functions

 Cache ()=default
 
 Cache (const std::size_t capacity)
 

Protected Attributes

std::size_t capacity_ {200}
 
std::function< bool(TKey &, TValue &)> on_eject_
 

Detailed Description

template<typename TKey, typename TValue>
class volcart::Cache< TKey, TValue >

Abstract Base Class for Key-Value Caches.

Template Parameters
TKeyKey type
TValueValue type

Definition at line 17 of file Cache.hpp.

Member Typedef Documentation

◆ Pointer

template<typename TKey , typename TValue >
using volcart::Cache< TKey, TValue >::Pointer = std::shared_ptr<Cache>

Shared Pointer Type

Definition at line 24 of file Cache.hpp.

Constructor & Destructor Documentation

◆ ~Cache()

template<typename TKey , typename TValue >
virtual volcart::Cache< TKey, TValue >::~Cache ( )
virtualdefault

Default destructor

◆ Cache() [1/2]

template<typename TKey , typename TValue >
volcart::Cache< TKey, TValue >::Cache ( )
protecteddefault

Default constructor

◆ Cache() [2/2]

template<typename TKey , typename TValue >
volcart::Cache< TKey, TValue >::Cache ( const std::size_t  capacity)
inlineexplicitprotected

Constructor with capacity

Definition at line 65 of file Cache.hpp.

Member Function Documentation

◆ capacity()

template<typename TKey , typename TValue >
virtual auto volcart::Cache< TKey, TValue >::capacity ( ) const -> std::size_t
pure virtual

Get the maximum number of elements in the cache.

Implemented in volcart::LRUCache< TKey, TValue, TMutex >.

◆ contains()

template<typename TKey , typename TValue >
virtual auto volcart::Cache< TKey, TValue >::contains ( const TKey &  k) -> bool
pure virtual

Check if an item is already in the cache.

Implemented in volcart::LRUCache< TKey, TValue, TMutex >.

◆ evict()

template<typename TKey , typename TValue >
virtual auto volcart::Cache< TKey, TValue >::evict ( ) -> void
pure virtual

Evict items following the cache policy.

Implemented in volcart::LRUCache< TKey, TValue, TMutex >.

◆ get()

template<typename TKey , typename TValue >
virtual auto volcart::Cache< TKey, TValue >::get ( const TKey &  k) -> TValue
pure virtual

Get an item from the cache by key.

Implemented in volcart::LRUCache< TKey, TValue, TMutex >.

◆ onEvict()

template<typename TKey , typename TValue >
virtual void volcart::Cache< TKey, TValue >::onEvict ( std::function< bool(TKey &, TValue &)>  fn)
pure virtual

Callback function when items are evicted.

Implemented in volcart::LRUCache< TKey, TValue, TMutex >.

◆ purge()

template<typename TKey , typename TValue >
virtual auto volcart::Cache< TKey, TValue >::purge ( ) -> void
pure virtual

Evict all items ignoring cache policy.

Implemented in volcart::LRUCache< TKey, TValue, TMutex >.

◆ put()

template<typename TKey , typename TValue >
virtual auto volcart::Cache< TKey, TValue >::put ( const TKey &  k,
const TValue &  v 
) -> void
pure virtual

Put an item into the cache.

Implemented in volcart::LRUCache< TKey, TValue, TMutex >.

◆ resetOnEvict()

template<typename TKey , typename TValue >
virtual void volcart::Cache< TKey, TValue >::resetOnEvict ( )
pure virtual

Remove the validation callback function.

Implemented in volcart::LRUCache< TKey, TValue, TMutex >.

◆ setCapacity()

template<typename TKey , typename TValue >
virtual void volcart::Cache< TKey, TValue >::setCapacity ( std::size_t  newCapacity)
pure virtual

Set the maximum number of elements in the cache.

Implemented in volcart::LRUCache< TKey, TValue, TMutex >.

◆ size()

template<typename TKey , typename TValue >
virtual auto volcart::Cache< TKey, TValue >::size ( ) const -> std::size_t
pure virtual

Get the current number of elements in the cache.

Implemented in volcart::LRUCache< TKey, TValue, TMutex >.

Member Data Documentation

◆ capacity_

template<typename TKey , typename TValue >
std::size_t volcart::Cache< TKey, TValue >::capacity_ {200}
protected

Maximum number of elements in the cache

Definition at line 68 of file Cache.hpp.

◆ on_eject_

template<typename TKey , typename TValue >
std::function<bool(TKey&, TValue&)> volcart::Cache< TKey, TValue >::on_eject_
protected

Callback to verify if an entry can be ejected

Definition at line 71 of file Cache.hpp.


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