Granada  1.54.0
Structured layer on top of C++ REST SDK for building server applications in C++. Granada implements sessions, server side plug-in framework, C++ OAuth 2.0 server, data storage access, server script running, server browsing.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | Protected Attributes | List of all members
granada::cache::SharedMapCacheDriver Class Reference

#include <shared_map_cache_driver.h>

Inheritance diagram for granada::cache::SharedMapCacheDriver:
granada::cache::CacheHandler

Public Member Functions

 SharedMapCacheDriver ()
 
virtual ~SharedMapCacheDriver ()
 
virtual const bool Exists (const std::string &key)
 
virtual const bool Exists (const std::string &hash, const std::string &key)
 
virtual const std::string Read (const std::string &key)
 
virtual const std::string Read (const std::string &hash, const std::string &key)
 
virtual void Write (const std::string &key, const std::string &value)
 
virtual void Write (const std::string &hash, const std::string &key, const std::string &value)
 
virtual void Destroy (const std::string &key)
 
virtual void Destroy (const std::string &hash, const std::string &key)
 
virtual bool Rename (const std::string &old_key, const std::string &new_key)
 
void Keys (const std::string &expression, std::vector< std::string > &keys)
 
virtual std::unique_ptr
< granada::cache::CacheHandlerIterator
make_iterator (const std::string &expression)
 
- Public Member Functions inherited from granada::cache::CacheHandler
 CacheHandler ()
 
virtual ~CacheHandler ()
 
virtual const void Match (const std::string &expression, std::vector< std::string > &keys)
 

Protected Attributes

std::unique_ptr
< std::unordered_map
< std::string, std::map
< std::string, std::string > > > 
data_
 
std::mutex mtx
 

Detailed Description

Manages the cache storing key-value pairs in an unordered map. unordered map |_ hash1 => map |_ key1 => value1 |_ key2 => value2 |_ hash2 => map |_ key1 => value3 |_ key2 => value4

This code is multi-thread safe.

Constructor & Destructor Documentation

granada::cache::SharedMapCacheDriver::SharedMapCacheDriver ( )

Constructor

virtual granada::cache::SharedMapCacheDriver::~SharedMapCacheDriver ( )
inlinevirtual

Destructor

Member Function Documentation

virtual void granada::cache::SharedMapCacheDriver::Destroy ( const std::string &  key)
virtual

Destroys a set of key-value pairs with the given name.

Parameters
hashName of the unordered map containing the key-value pairs

Implements granada::cache::CacheHandler.

virtual void granada::cache::SharedMapCacheDriver::Destroy ( const std::string &  hash,
const std::string &  key 
)
virtual

Destroys a key value pair of a given set.

Parameters
hashName of the unordered map containing the key-value pair to destroy.
keyKey associated with the value to destroy.

Implements granada::cache::CacheHandler.

virtual const bool granada::cache::SharedMapCacheDriver::Exists ( const std::string &  key)
virtual

Checks if a key exist in the cache.

Parameters
keyKey to check.

Implements granada::cache::CacheHandler.

virtual const bool granada::cache::SharedMapCacheDriver::Exists ( const std::string &  hash,
const std::string &  key 
)
virtual

Checks if a key exist in a set with given hash.

Parameters
hashName of the set of key-value.
keyKey of the value
Returns
True if exist, false if it does not.

Implements granada::cache::CacheHandler.

void granada::cache::SharedMapCacheDriver::Keys ( const std::string &  expression,
std::vector< std::string > &  keys 
)

Fills a vector with keys of the cache that match a given expression.

Parameters
expressionExpression used to match keys.
               Example of expression:

                   session:value:*
                   => will retrieve all the keys that start with
                   session:values: stored in the cache.

                   *:value:*
                   => will retrieve all the keys that contain
                   ":value:"
Returns
Vector of string keys.
virtual std::unique_ptr<granada::cache::CacheHandlerIterator> granada::cache::SharedMapCacheDriver::make_iterator ( const std::string &  expression)
inlinevirtual

Returns an iterator to iterate over keys with an expression.

Parameters
Expressionto be use to iterate over keys that match this expression. Example: "user*" => we will iterate over all the keys that start with "user"
Returns
Iterator.

Implements granada::cache::CacheHandler.

virtual const std::string granada::cache::SharedMapCacheDriver::Read ( const std::string &  key)
virtual

Returns value from the cache.

Parameters
keyKey of the value.
Returns
Value

Implements granada::cache::CacheHandler.

virtual const std::string granada::cache::SharedMapCacheDriver::Read ( const std::string &  hash,
const std::string &  key 
)
virtual

Returns the value of a key-value pair stored in an map with the given name.

Parameters
hashName of the map.
keyKey to identify the value.
Returns
Value.

Implements granada::cache::CacheHandler.

virtual bool granada::cache::SharedMapCacheDriver::Rename ( const std::string &  old_key,
const std::string &  new_key 
)
virtual

Renames a key if it does not already exists.

Parameters
old_keyOld key to rename.
new_keyNew key.
Returns
True if the key could be renamed, false if not, for example it will return false if the new key already existed.

Implements granada::cache::CacheHandler.

virtual void granada::cache::SharedMapCacheDriver::Write ( const std::string &  key,
const std::string &  value 
)
virtual

Set a value in the cache associated with a given key.

Parameters
keyKey of the value.
valueValue.

Implements granada::cache::CacheHandler.

virtual void granada::cache::SharedMapCacheDriver::Write ( const std::string &  hash,
const std::string &  key,
const std::string &  value 
)
virtual

Inserts or rewrite a key-value pair in a map with the given name. If the set does not exist, it creates it.

Parameters
hashName of the map.
keyKey to identify the value.
Value.

Implements granada::cache::CacheHandler.

Member Data Documentation

std::unique_ptr<std::unordered_map<std::string,std::map<std::string,std::string> > > granada::cache::SharedMapCacheDriver::data_
protected

Map where all data is stored.

std::mutex granada::cache::SharedMapCacheDriver::mtx
protected

Mutex for thread safety.


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