C++ Discord API Bot Library
|Construct a new cache object. More...
|Destroy the cache object. More...
|store (T *object)
|Store an object in the cache. Passing a nullptr will have no effect. More...
|remove (T *object)
|Remove an object from the cache. More...
|find (snowflake id)
|Find an object in the cache by id. More...
|Return a count of the number of items in the cache. More...
|Return the cache's locking mutex. More...
|Get the container unordered map. More...
|"Rehash" a cache by reallocating the map and copying all elements into the new one. More...
|Get "real" size in RAM of the cached objects. More...
A cache object maintains a cache of dpp::managed objects.
This is for example users, channels or guilds. You may instantiate your own caches, to contain any type derived from dpp::managed including your own types.
|class type to store, which should be derived from dpp::managed.
Construct a new cache object.
Destroy the cache object.
Get "real" size in RAM of the cached objects.
This does not include metadata used to maintain the unordered map itself.
Return a count of the number of items in the cache.
This is used by the library e.g. to count guilds, users, and roles stored within caches. get
Find an object in the cache by id.
|Object snowflake id to find
Return the cache's locking mutex.
Use this whenever you manipulate or iterate raw elements in the cache!
std::shared_lock, else wrap it in a
std::unique_lock. Shared locks will allow for multiple readers whilst blocking writers, and unique locks will allow only one writer whilst blocking readers and writers.
"Rehash" a cache by reallocating the map and copying all elements into the new one.
Over a long running timeframe, unordered maps can grow in size due to bucket allocation, this function frees that unused memory to keep the maps in control over time. If this is an issue which is apparent with your use of dpp::cache objects, you should periodically call this method.
Remove an object from the cache.
|object to remove. Passing a nullptr will have no effect.
Store an object in the cache. Passing a nullptr will have no effect.
The object must be derived from dpp::managed and should be allocated on the heap. Generally this is done via
new. Once stored in the cache the lifetime of the stored object is managed by the cache class unless the cache is deleted (at which point responsibility for deleting the object returns to its allocator). Objects stored are removed when the cache::remove() method is called by placing them into a garbage collection queue for deletion within the next 60 seconds, which are then deleted in bulk for efficiency and to aid thread safety.
|object to store. Storing a pointer to the cache relinquishes ownership to the cache object.