libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats > Class Template Reference

A read-only cache that returns a const reference to the range data. More...

#include <cache.hpp>

Inheritance diagram for jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >:
[legend]
Collaboration diagram for jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >:
[legend]

Public Types

typedef base< Factory > base_t
 
typedef base_t::factory_type factory_type
 The actual factory type. More...
 
typedef base_t::key_type key_type
 The type of the key. More...
 
typedef ThrT thread_traits
 The type of threading in force. More...
 
typedef Stats statistics_type
 The statistics that will be gathered. More...
 
typedef thread_traits::assoc_colln_t colln_t
 The type of the internal associative collection. More...
 
typedef colln_t::size_type size_type
 The size type of the internal associative collection. More...
 
typedef const thread_traits::mapped_type mapped_type
 The range-data type of the key type. More...
 
typedef thread_traits::flusher_pool_t::exception_type exception_type
 The base class from which the exceptions that will be thrown by this class are derived. More...
 
typedef thread_traits::flusher_pool_t::pool_traits_type::os_traits os_traits
 
typedef os_traits::lock_traits lock_traits
 
- Public Types inherited from jmmcg::LIBJMMCG_VER_NAMESPACE::cache::base< Factory >
typedef Factory factory_type
 The factory that is used to create a range-data value for a particular key. More...
 
typedef factory_type::key_type key_type
 The type of the key. More...
 
typedef factory_type::value_type value_type
 The type of the range-data. More...
 

Public Member Functions

constexpr __stdcall ro (const size_type low_water, const size_type high_water, const typename thread_traits::populate_pool_t::pool_type::size_type num_threads, const factory_type &f)
 Create an empty read-only cache. More...
 
template<typename Iter >
constexpr __stdcall ro (const size_type low_water, const size_type high_water, const typename thread_traits::populate_pool_t::pool_type::size_type num_threads, const factory_type &f, const Iter &beg, const Iter &end)
 Create a read-only cache and populate it with some values. More...
 
__stdcall ro (const ro &)
 
virtual __stdcall ~ro (void) noexcept(true)
 
ro &__fastcall operator= (const ro &)
 
bool __fastcall empty (void) const noexcept(true) override
 Indicate if the cache is empty. More...
 
const size_type __fastcall size (void) const noexcept(true)
 Indicate the number of data items in the cache. More...
 
void __fastcall clear (void) override
 Synchronously remove all data within the cache. More...
 
template<typename Iter >
void __fastcall insert (const Iter &beg, const Iter &end)
 Synchronously insert a range of values into the cache. More...
 
const mapped_type __fastcall operator[] (const key_type &key)
 Lookup and return the range-data value associated with a key from the map. More...
 
void __fastcall flush (void) override
 A synchronous call to flush the cache according to the flush policy. More...
 
const statistics_type &__fastcall statistics (void) const noexcept(true)
 
- Public Member Functions inherited from jmmcg::LIBJMMCG_VER_NAMESPACE::cache::base< Factory >
__stdcall base (const base &)
 
virtual __stdcall ~base (void) noexcept(true)
 
base &__fastcall operator= (const base &)
 

Public Attributes

const size_type low_water_mark
 The "low water mark" of the cache. More...
 
const size_type high_water_mark
 The "high water mark" of the cache. More...
 

Additional Inherited Members

- Protected Member Functions inherited from jmmcg::LIBJMMCG_VER_NAMESPACE::cache::base< Factory >
__stdcall base (const factory_type &f)
 
const factory_type &__fastcall data_factory () const noexcept(true)
 

Detailed Description

template<class Factory, class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
class jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >

A read-only cache that returns a const reference to the range data.

The cache is a value-type, so you can have caches of caches.

Definition at line 376 of file cache.hpp.

Member Typedef Documentation

◆ base_t

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
typedef base<Factory> jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::base_t

Definition at line 378 of file cache.hpp.

◆ colln_t

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
typedef thread_traits::assoc_colln_t jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::colln_t

The type of the internal associative collection.

Definition at line 383 of file cache.hpp.

◆ exception_type

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
typedef thread_traits::flusher_pool_t::exception_type jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::exception_type

The base class from which the exceptions that will be thrown by this class are derived.

Definition at line 386 of file cache.hpp.

◆ factory_type

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
typedef base_t::factory_type jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::factory_type

The actual factory type.

Definition at line 379 of file cache.hpp.

◆ key_type

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
typedef base_t::key_type jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::key_type

The type of the key.

Definition at line 380 of file cache.hpp.

◆ lock_traits

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
typedef os_traits::lock_traits jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::lock_traits

Definition at line 388 of file cache.hpp.

◆ mapped_type

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
typedef const thread_traits::mapped_type jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::mapped_type

The range-data type of the key type.

Definition at line 385 of file cache.hpp.

◆ os_traits

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
typedef thread_traits::flusher_pool_t::pool_traits_type::os_traits jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::os_traits

Definition at line 387 of file cache.hpp.

◆ size_type

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
typedef colln_t::size_type jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::size_type

The size type of the internal associative collection.

Definition at line 384 of file cache.hpp.

◆ statistics_type

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
typedef Stats jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::statistics_type

The statistics that will be gathered.

Definition at line 382 of file cache.hpp.

◆ thread_traits

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
typedef ThrT jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::thread_traits

The type of threading in force.

Definition at line 381 of file cache.hpp.

Constructor & Destructor Documentation

◆ ro() [1/3]

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
constexpr __stdcall jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::ro ( const size_type  low_water,
const size_type  high_water,
const typename thread_traits::populate_pool_t::pool_type::size_type  num_threads,
const factory_type f 
)
inlineexplicitconstexpr

Create an empty read-only cache.

Parameters
low_waterThis is the low_water_mark of the cache. i.e. using the flush policy the cache will attempt to ensure that size()>=low_water_mark.
high_waterThis is the high_water_mark of the cache. i.e. using the flush policy the cache will attempt to ensure that size()<=high_water_mark.
num_threadsThis is the number of threads in the thread pool used for creating range-data for satisfying data requests. This number is set to prevent any data source (e.g. a database) from becoming overwhelmed by requests.
fThe factory that is used to create a range-data item for a particular key.
See also
size()

Definition at line 413 of file cache.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::high_water_mark, and jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::low_water_mark.

◆ ro() [2/3]

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
template<typename Iter >
constexpr __stdcall jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::ro ( const size_type  low_water,
const size_type  high_water,
const typename thread_traits::populate_pool_t::pool_type::size_type  num_threads,
const factory_type f,
const Iter &  beg,
const Iter &  end 
)
inlineconstexpr

Create a read-only cache and populate it with some values.

Note that a (possibly) asynchronous flush() may occur after the population to ensure that the max_size of the cache is maintained.

Parameters
low_waterThis is the low_water_mark of the cache. i.e. using the flush policy the cache will attempt to ensure that size()>=low_water_mark.
high_waterThis is the high_water_mark of the cache. i.e. using the flush policy the cache will attempt to ensure that size()<=high_water_mark.
num_threadsThis is the number of threads in the thread pool used for creating range-data for satisfying data requests. This number is set to prevent any data source (e.g. a database) from becoming overwhelmed by requests.
fThe factory that is used to create a range-data item for a particular key.
begAn iterator to the beginning of the source data.
endAn iterator to the end of the source data.
See also
size()
insert()

Definition at line 430 of file cache.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::high_water_mark, and jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::low_water_mark.

◆ ro() [3/3]

template<class Factory , class FP , class ThrT , class Stats >
jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::ro ( const ro< Factory, FP, ThrT, Stats > &  r)
inline

◆ ~ro()

template<class Factory , class FP , class ThrT , class Stats >
jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::~ro ( void  )
inlinevirtualnoexcept

Definition at line 171 of file cache_impl.hpp.

Member Function Documentation

◆ clear()

template<class Factory , class FP , class ThrT , class Stats >
void jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::clear ( void  )
inlineoverridevirtual

Synchronously remove all data within the cache.

Note that this does not take into account any outstanding cache fills nor flush()s. Thus after this function it is not guaranteed that empty()==true. This function will reset any statistics upon clearing all contents from the cache.

See also
flush()
empty()

Implements jmmcg::LIBJMMCG_VER_NAMESPACE::cache::base< Factory >.

Definition at line 200 of file cache_impl.hpp.

◆ empty()

template<class Factory , class FP , class ThrT , class Stats >
bool jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::empty ( void  ) const
inlineoverridevirtualnoexcept

Indicate if the cache is empty.

Note that this does not take into account any outstanding cache fills nor flush()s.

Returns
"true" iff size()==0.
See also
size()
flush()

Implements jmmcg::LIBJMMCG_VER_NAMESPACE::cache::base< Factory >.

Definition at line 188 of file cache_impl.hpp.

◆ flush()

template<class Factory , class FP , class ThrT , class Stats >
void jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::flush ( void  )
inlineoverridevirtual

A synchronous call to flush the cache according to the flush policy.

Note that if two or more items within the cache satisfy the victimization criterion, and removing at least one of them would ensure that the max_size criterion is satisfied, it is implementation defined regarding which of those items woulsd be flushed.

Implements jmmcg::LIBJMMCG_VER_NAMESPACE::cache::base< Factory >.

Definition at line 236 of file cache_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::high_water_mark, and jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::low_water_mark.

◆ insert()

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
template<typename Iter >
void __fastcall jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::insert ( const Iter &  beg,
const Iter &  end 
)
inline

Synchronously insert a range of values into the cache.

Note that a (possibly) asynchronous flush() may occur after the population to ensure that the size()~<=high_water_mark of the cache is maintained.

Parameters
begAn iterator to the beginning of the source data.
endAn iterator to the end of the source data.
See also
flush()

Definition at line 471 of file cache.hpp.

◆ operator=()

template<class Factory , class FP , class ThrT , class Stats >
ro< Factory, FP, ThrT, Stats > & jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::operator= ( const ro< Factory, FP, ThrT, Stats > &  r)
inline

◆ operator[]()

template<class Factory , class FP , class ThrT , class Stats >
const ro< Factory, FP, ThrT, Stats >::mapped_type jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::operator[] ( const key_type key)
inline

Lookup and return the range-data value associated with a key from the map.

The creation of the range-data value may be asynchronous, as an implementation-defined optimization for multi-threaded caches. A (possibly) asynchronous flush() is called to ensure that the high_water_mark is not exceeded before this function returns. Note that for asynchronous calls to flush(), they are only run once: overlapping calls to flush() will cause the later calls to be quashed, such that no buffering of flush()es occurs. Note that it is guaranteed that empty()==false after this call.

Parameters
keyThe key to look up in the map and return the range-data value.
Returns
A const-qualified copy of the range data value associated with the key. This ensures that if an asynchronous flush() of the data item occurs, this will not leave a dangling reference in the client.
See also
flush()
empty()

Definition at line 207 of file cache_impl.hpp.

◆ size()

template<class Factory , class FP , class ThrT , class Stats >
const ro< Factory, FP, ThrT, Stats >::size_type jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::size ( void  ) const
inlinenoexcept

Indicate the number of data items in the cache.

Note that this does not take into account any outstanding cache fills nor flush()s.

See also
flush()

Definition at line 194 of file cache_impl.hpp.

◆ statistics()

template<class Factory , class FP , class ThrT , class Stats >
const Stats & jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::statistics ( void  ) const
inlinenoexcept

Definition at line 253 of file cache_impl.hpp.

Member Data Documentation

◆ high_water_mark

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
const size_type jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::high_water_mark

The "high water mark" of the cache.

The flush policy will attempt to ensure that size()<=high_water_mark. But this is not guaranteed, because there may be outstanding cache fills from another thread.

See also
size()

Definition at line 403 of file cache.hpp.

Referenced by jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::flush(), jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::operator=(), and jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::ro().

◆ low_water_mark

template<class Factory , class FP = lru<typename Factory::value_type>, class ThrT = typename threading<typename Factory::key_type,FP>::template single<ppd::platform_api>, class Stats = no_statistics>
const size_type jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::low_water_mark

The "low water mark" of the cache.

The flush policy will attempt to ensure that size()>=low_water_mark. But this is not guaranteed, because there may be outstanding cache fills from another thread.

See also
size()

Definition at line 396 of file cache.hpp.

Referenced by jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::flush(), jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::operator=(), and jmmcg::LIBJMMCG_VER_NAMESPACE::cache::ro< Factory, FP, ThrT, Stats >::ro().


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