Hot cache meant for storing string keys and void pointer values.
◆ M_cache_strvp_t
◆ M_cache_strvp_flags_t
Flags for controlling the behavior of the hash
Enumerator |
---|
M_CACHE_STRVP_NONE | Default.
|
M_CACHE_STRVP_CASECMP | Compare keys case insensitive.
|
◆ M_cache_strvp_create()
M_cache_strvp_t * M_cache_strvp_create |
( |
size_t |
max_size, |
|
|
M_uint32 |
flags, |
|
|
void(*)(void *) |
destroy_func |
|
) |
| |
Create a cache.
- Parameters
-
[in] | max_size | Maximum number of entries in the cache. |
[in] | flags | M_hash_strvp_flags_t flags for modifying behavior. |
[in] | destroy_func | The function to be called to destroy value when removed. |
- Returns
- Allocated cache.
- See also
- M_cache_strvp_destroy
◆ M_cache_strvp_destroy()
Destroy the cache.
- Parameters
-
◆ M_cache_strvp_insert()
M_bool M_cache_strvp_insert |
( |
M_cache_strvp_t * |
c, |
|
|
const char * |
key, |
|
|
const void * |
value |
|
) |
| |
Insert an entry into the cache.
- Parameters
-
[in] | c | Cache being referenced. |
[in] | key | Key to insert. |
[in] | value | Value to insert into h. The c will take ownership of the value. Maybe NULL. |
- Returns
- M_TRUE on success, or M_FALSE on failure.
◆ M_cache_strvp_remove()
Remove an entry from the cache.
- Parameters
-
[in] | c | Cache being referenced. |
[in] | key | Key to remove from the h. |
- Returns
- M_TRUE on success, or M_FALSE if key does not exist.
◆ M_cache_strvp_get()
M_bool M_cache_strvp_get |
( |
const M_cache_strvp_t * |
c, |
|
|
const char * |
key, |
|
|
void ** |
value |
|
) |
| |
Retrieve the value for a key from the cache.
- Parameters
-
[in] | c | Cache being referenced. |
[in] | key | Key for value. |
[out] | value | Pointer to value stored in the h. Optional, pass NULL if not needed. |
- Returns
- M_TRUE if value retrieved, M_FALSE if key does not exist.
◆ M_cache_strvp_get_direct()
void * M_cache_strvp_get_direct |
( |
const M_cache_strvp_t * |
c, |
|
|
const char * |
key |
|
) |
| |
Retrieve the value for a key from the cache, and return it directly as the return value.
This cannot be used if you need to differentiate between a key that doesn't exist vs a key with a NULL value.
- Parameters
-
[in] | c | Cache being referenced. |
[in] | key | Key for value to retrieve from the hashtable. A NULL or empty string is explicitly disallowed. |
- Returns
- NULL if key doesn't exist or NULL value on file, otherwise the value.
◆ M_cache_strvp_size()
Get the number of items in the cache.
- Parameters
-
[in] | c | Cache being referenced. |
- Returns
- Count.
◆ M_cache_strvp_max_size()
Get the maximum number of items allowed in the cache.
- Parameters
-
[in] | c | Cache being referenced. |
- Returns
- Max.
◆ M_cache_strvp_set_max_size()
Set the maximum number of items allowed in the cache.
This can be used to increase or decrease the maximum size of the cache. If the max size is smaller than the number of items in the cache, older items will be removed.
- Parameters
-
[in] | c | Cache being referenced. |
[in] | max_size | Maximum size. |
- Returns
- M_TRUE if the max size was changed, otherwise M_FALSE on error.