mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-01 08:25:51 +00:00
Update Doxyfile and add some documentation for keyCache
This commit is contained in:
6
Doxyfile
6
Doxyfile
@@ -17,7 +17,11 @@
|
|||||||
# directories like "/usr/src/myproject". Separate the files or directories
|
# directories like "/usr/src/myproject". Separate the files or directories
|
||||||
# with spaces.
|
# with spaces.
|
||||||
|
|
||||||
INPUT = modules src/cpp/ripple
|
INPUT = \
|
||||||
|
modules \
|
||||||
|
src/cpp/ripple
|
||||||
|
|
||||||
|
#modules/ripple_basics/containers/ripple_KeyCache.h
|
||||||
|
|
||||||
|
|
||||||
# If the value of the INPUT tag contains directories, you can use the
|
# If the value of the INPUT tag contains directories, you can use the
|
||||||
|
|||||||
@@ -1,51 +1,73 @@
|
|||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef RIPPLE_KEYCACHE_H
|
#ifndef RIPPLE_KEYCACHE_H
|
||||||
#define RIPPLE_KEYCACHE_H
|
#define RIPPLE_KEYCACHE_H
|
||||||
|
|
||||||
/** Maintains a cache of keys with no associated data
|
/** Maintains a cache of keys with no associated data.
|
||||||
|
|
||||||
Timer must have this interface:
|
The cache has a target size and an expiration time. When cached items become
|
||||||
|
older than the maximum age they are eligible for removal during a
|
||||||
|
call to @ref sweep.
|
||||||
|
|
||||||
static int Timer::getElapsedSeconds ();
|
@note
|
||||||
|
Timer must provide this function:
|
||||||
|
@code
|
||||||
|
static int getElapsedSeconds ();
|
||||||
|
@endcode
|
||||||
|
|
||||||
|
file vf_db.h
|
||||||
|
@ingroup ripple_basics
|
||||||
*/
|
*/
|
||||||
template <typename c_Key, class Timer>
|
template <class Key, class Timer>
|
||||||
class KeyCache
|
class KeyCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef c_Key key_type;
|
/** Provides a type for the key.
|
||||||
typedef boost::unordered_map<key_type, int> map_type;
|
*/
|
||||||
typedef typename map_type::iterator map_iterator;
|
typedef Key key_type;
|
||||||
|
|
||||||
protected:
|
/** Construct with the specified name.
|
||||||
const std::string mName;
|
|
||||||
boost::mutex mNCLock;
|
|
||||||
map_type mCache;
|
|
||||||
unsigned int mTargetSize, mTargetAge;
|
|
||||||
|
|
||||||
public:
|
@param size The initial target size.
|
||||||
|
@param age The initial expiration time.
|
||||||
KeyCache(const std::string& name, int size = 0, int age = 120) : mName(name), mTargetSize(size), mTargetAge(age)
|
*/
|
||||||
|
KeyCache (const std::string& name,
|
||||||
|
int size = 0,
|
||||||
|
int age = 120) : mName(name), mTargetSize(size), mTargetAge(age)
|
||||||
{
|
{
|
||||||
assert((size >= 0) && (age > 2));
|
assert((size >= 0) && (age > 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void getSize()
|
/** Returns the current size.
|
||||||
|
*/
|
||||||
|
unsigned int getSize ()
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock sl(mNCLock);
|
boost::mutex::scoped_lock sl(mNCLock);
|
||||||
return mCache.size();
|
return mCache.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void getTargetSize()
|
/** Returns the desired target size.
|
||||||
|
*/
|
||||||
|
unsigned int getTargetSize ()
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock sl(mNCLock);
|
boost::mutex::scoped_lock sl(mNCLock);
|
||||||
return mTargetSize;
|
return mTargetSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getTargetAge()
|
/** Returns the desired target age.
|
||||||
|
*/
|
||||||
|
unsigned int getTargetAge ()
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock sl(mNCLock);
|
boost::mutex::scoped_lock sl(mNCLock);
|
||||||
return mTargetAge;
|
return mTargetAge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Simultaneously set the target size and age.
|
||||||
|
|
||||||
|
@param size The target size.
|
||||||
|
@param age The target age.
|
||||||
|
*/
|
||||||
void setTargets(int size, int age)
|
void setTargets(int size, int age)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock sl(mNCLock);
|
boost::mutex::scoped_lock sl(mNCLock);
|
||||||
@@ -54,13 +76,21 @@ public:
|
|||||||
assert((mTargetSize >= 0) && (mTargetAge > 2));
|
assert((mTargetSize >= 0) && (mTargetAge > 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Retrieve the name of this object.
|
||||||
|
*/
|
||||||
const std::string& getName()
|
const std::string& getName()
|
||||||
{
|
{
|
||||||
return mName;
|
return mName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Determine if the specified key is cached, and optionally refresh it.
|
||||||
|
|
||||||
|
@param key The key to check
|
||||||
|
@param refresh Whether or not to refresh the entry.
|
||||||
|
@return `true` if the key was found.
|
||||||
|
*/
|
||||||
bool isPresent(const key_type& key, bool refresh = true)
|
bool isPresent(const key_type& key, bool refresh = true)
|
||||||
{ // Check if an entry is cached, refresh it if so
|
{
|
||||||
boost::mutex::scoped_lock sl(mNCLock);
|
boost::mutex::scoped_lock sl(mNCLock);
|
||||||
|
|
||||||
map_iterator it = mCache.find(key);
|
map_iterator it = mCache.find(key);
|
||||||
@@ -71,8 +101,13 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Remove the specified cache entry.
|
||||||
|
|
||||||
|
@param key The key to remove.
|
||||||
|
@return `false` if the key was not found.
|
||||||
|
*/
|
||||||
bool del(const key_type& key)
|
bool del(const key_type& key)
|
||||||
{ // Remove an entry from the cache, return false if not-present
|
{
|
||||||
boost::mutex::scoped_lock sl(mNCLock);
|
boost::mutex::scoped_lock sl(mNCLock);
|
||||||
|
|
||||||
map_iterator it = mCache.find(key);
|
map_iterator it = mCache.find(key);
|
||||||
@@ -83,8 +118,13 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool add(const key_type& key)
|
/** Add the specified cache entry.
|
||||||
{ // Add an entry to the cache, return true if it is new
|
|
||||||
|
@param key The key to add.
|
||||||
|
@return `true` if the key did not previously exist.
|
||||||
|
*/
|
||||||
|
bool add (const key_type& key)
|
||||||
|
{
|
||||||
boost::mutex::scoped_lock sl(mNCLock);
|
boost::mutex::scoped_lock sl(mNCLock);
|
||||||
|
|
||||||
map_iterator it = mCache.find(key);
|
map_iterator it = mCache.find(key);
|
||||||
@@ -97,8 +137,10 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sweep()
|
/** Remove stale entries from the cache.
|
||||||
{ // Remove stale entries from the cache
|
*/
|
||||||
|
void sweep ()
|
||||||
|
{
|
||||||
int now = Timer::getElapsedSeconds ();
|
int now = Timer::getElapsedSeconds ();
|
||||||
boost::mutex::scoped_lock sl(mNCLock);
|
boost::mutex::scoped_lock sl(mNCLock);
|
||||||
|
|
||||||
@@ -121,11 +163,29 @@ public:
|
|||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
else if (it->second < target)
|
else if (it->second < target)
|
||||||
|
{
|
||||||
it = mCache.erase(it);
|
it = mCache.erase(it);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
++it;
|
++it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/** Provides a type for the underlying map.
|
||||||
|
*/
|
||||||
|
typedef boost::unordered_map<key_type, int> map_type;
|
||||||
|
|
||||||
|
/** The type of the iterator used for traversals.
|
||||||
|
*/
|
||||||
|
typedef typename map_type::iterator map_iterator;
|
||||||
|
|
||||||
|
std::string const mName;
|
||||||
|
boost::mutex mNCLock;
|
||||||
|
map_type mCache;
|
||||||
|
unsigned int mTargetSize, mTargetAge;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1680,6 +1680,7 @@
|
|||||||
<ClInclude Include="src\cpp\websocketpp\src\websocket_frame.hpp" />
|
<ClInclude Include="src\cpp\websocketpp\src\websocket_frame.hpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include="Doxyfile" />
|
||||||
<None Include="modules\ripple_json\json\json_internalarray.inl" />
|
<None Include="modules\ripple_json\json\json_internalarray.inl" />
|
||||||
<None Include="modules\ripple_json\json\json_internalmap.inl" />
|
<None Include="modules\ripple_json\json\json_internalmap.inl" />
|
||||||
<None Include="modules\ripple_json\json\json_valueiterator.inl" />
|
<None Include="modules\ripple_json\json\json_valueiterator.inl" />
|
||||||
|
|||||||
@@ -94,9 +94,6 @@
|
|||||||
<Filter Include="1. Modules\ripple_mess\containers">
|
<Filter Include="1. Modules\ripple_mess\containers">
|
||||||
<UniqueIdentifier>{683c494b-1175-49ac-9714-65640ba50bf5}</UniqueIdentifier>
|
<UniqueIdentifier>{683c494b-1175-49ac-9714-65640ba50bf5}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter Include="1. Modules\ripple_mess\protobuf">
|
|
||||||
<UniqueIdentifier>{eb0c6bda-cf68-4334-a8c3-8d39202852a0}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="1. Modules\ripple_mess\types">
|
<Filter Include="1. Modules\ripple_mess\types">
|
||||||
<UniqueIdentifier>{1b463564-35d9-43d1-b3a0-21b344a3a1c7}</UniqueIdentifier>
|
<UniqueIdentifier>{1b463564-35d9-43d1-b3a0-21b344a3a1c7}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
@@ -1479,6 +1476,7 @@
|
|||||||
<None Include="modules\ripple_json\json\json_valueiterator.inl">
|
<None Include="modules\ripple_json\json\json_valueiterator.inl">
|
||||||
<Filter>1. Modules\ripple_json\json</Filter>
|
<Filter>1. Modules\ripple_json\json</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="Doxyfile" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<CustomBuild Include="src\cpp\ripple\ripple.proto" />
|
<CustomBuild Include="src\cpp\ripple\ripple.proto" />
|
||||||
|
|||||||
Reference in New Issue
Block a user