bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
ngap::MemoryCache< VALUE > Class Template Reference

A simple memory cache. More...

#include <MemoryCache.h>

Inheritance diagram for ngap::MemoryCache< VALUE >:
Inheritance graph
Collaboration diagram for ngap::MemoryCache< VALUE >:
Collaboration graph

Public Member Functions

virtual void clear ()
 Clear the cache.
 
virtual bool get (const std::string &key, VALUE &value)
 Get the item from the cache. If the item is not in the cache, the value-result parameter is not modified.
 
virtual bool initialize (int max_items, int purge_items)
 Initialize the cache.
 
 MemoryCache (const MemoryCache *src)=delete
 
MemoryCacheoperator= (const MemoryCache *src)=delete
 
virtual void put (const std::string &key, const VALUE &value)
 Put the item in the cache. If the key is already in the cache, the value is updated.
 
virtual unsigned long size () const
 How many items are in the cache.
 

Friends

class MemoryCacheTest
 

Detailed Description

template<typename VALUE>
class ngap::MemoryCache< VALUE >

A simple memory cache.

This is a header-only class. It is used by NgapRequestHandler to cache string values. It could be tested more completely and used in other places.

The cache implements a simple FIFO queue to purge the oldest entries when the cache is full. Purging is done when the count of cached items exceeds the maximum number of items allowed in the cache. The private purge method will remove the oldest P entries from the cache where P is the number of 'purge items' as set with the initialize() method.

Instead of initializing the cache (setting the max and purge item counts) using a constructor, am initialize() method is used. The constructors never throw exceptions. If initialize() fails, it returns false. The get() and put() methods may throw exceptions.

The cache is not thread-safe.

Template Parameters
VALUEAs of 10/17/23 only tested with std::string

Definition at line 64 of file MemoryCache.h.

Member Function Documentation

◆ clear()

template<typename VALUE>
virtual void ngap::MemoryCache< VALUE >::clear ( )
inlinevirtual

Clear the cache.

Definition at line 166 of file MemoryCache.h.

◆ get()

template<typename VALUE>
virtual bool ngap::MemoryCache< VALUE >::get ( const std::string & key,
VALUE & value )
inlinevirtual

Get the item from the cache. If the item is not in the cache, the value-result parameter is not modified.

Parameters
key
valueValue-result parameter; operator=() is used to copy the value of the cached item.
Returns
Return True if the item is in the cache, false otherwise.

Definition at line 133 of file MemoryCache.h.

◆ initialize()

template<typename VALUE>
virtual bool ngap::MemoryCache< VALUE >::initialize ( int max_items,
int purge_items )
inlinevirtual

Initialize the cache.

Parameters
max_itemsMust be greater than zero
purge_itemsMust be greater than zero
Returns
Return True if the cache was initialized, false otherwise.

Definition at line 117 of file MemoryCache.h.

◆ put()

template<typename VALUE>
virtual void ngap::MemoryCache< VALUE >::put ( const std::string & key,
const VALUE & value )
inlinevirtual

Put the item in the cache. If the key is already in the cache, the value is updated.

Parameters
key
value

Definition at line 149 of file MemoryCache.h.

◆ size()

template<typename VALUE>
virtual unsigned long ngap::MemoryCache< VALUE >::size ( ) const
inlinevirtual

How many items are in the cache.

Definition at line 163 of file MemoryCache.h.

Friends And Related Symbol Documentation

◆ MemoryCacheTest

template<typename VALUE>
friend class MemoryCacheTest
friend

Definition at line 102 of file MemoryCache.h.


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