ModErn Text Analysis
META Enumerates Textual Applications
Public Member Functions | Private Attributes | List of all members
meta::caching::generic_shard_cache< Key, Value, Map > Class Template Reference

A simple sharding-based approach for increasing concurrency within a cache. More...

#include <shard_cache.h>

Public Member Functions

template<class... Args>
 generic_shard_cache (uint8_t shards, Args &&...args)
 Constructs a shard cache with the given number of shards, passing any additional parameters to the underlying Map classes created. More...
 
 generic_shard_cache (generic_shard_cache &&)=default
 generic_shard_cache may be move constructed
 
generic_shard_cacheoperator= (generic_shard_cache &&)=default
 generic_shard_cache may be move assigned
 
 ~generic_shard_cache ()=default
 Default destructor.
 
void insert (const Key &key, const Value &value)
 Inserts a given (key, value) pair into the cache. More...
 
util::optional< Value > find (const Key &key)
 Finds a value in the cache. More...
 

Private Attributes

std::vector< Map< Key, Value > > shards_
 The Map for each shard.
 
std::hash< Key > hasher_
 The hash function used for determining which shard a key belongs to.
 

Detailed Description

template<class Key, class Value, template< class, class > class Map>
class meta::caching::generic_shard_cache< Key, Value, Map >

A simple sharding-based approach for increasing concurrency within a cache.

Wraps a given number of Maps, each used to contain a segment of the keyspace. It is assumed that the Map class is self-synchronizing (i.e., it has a mutex or other concurrency safety mechanism built in).

Constructor & Destructor Documentation

template<class Key , class Value , template< class, class > class Map>
template<class... Args>
meta::caching::generic_shard_cache< Key, Value, Map >::generic_shard_cache ( uint8_t  shards,
Args &&...  args 
)

Constructs a shard cache with the given number of shards, passing any additional parameters to the underlying Map classes created.

Parameters
shardsthe number of shards to create
argsthe remaining arguments to be used in creating the Map for each shard

Member Function Documentation

template<class Key , class Value , template< class, class > class Map>
void meta::caching::generic_shard_cache< Key, Value, Map >::insert ( const Key &  key,
const Value &  value 
)

Inserts a given (key, value) pair into the cache.

Parameters
key
value
template<class Key , class Value , template< class, class > class Map>
util::optional< Value > meta::caching::generic_shard_cache< Key, Value, Map >::find ( const Key &  key)

Finds a value in the cache.

If it exists, the optional will be engaged, otherwise, it will be disengaged.

Parameters
keythe key to find the corresponding value for
Returns
an optional that may contain the value, if found

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