From: Vsevolod Stakhov Date: Sat, 20 May 2017 08:48:20 +0000 (+0100) Subject: [Minor] Allow explicit deletion from LRU cache X-Git-Tag: 1.6.0~162 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bc5cf4c2403854857c61025b8a19ab5abb2e28df;p=rspamd.git [Minor] Allow explicit deletion from LRU cache --- diff --git a/src/libutil/hash.c b/src/libutil/hash.c index 591af9027..1afe947ee 100644 --- a/src/libutil/hash.c +++ b/src/libutil/hash.c @@ -342,6 +342,23 @@ rspamd_lru_hash_lookup (rspamd_lru_hash_t *hash, gconstpointer key, time_t now) return NULL; } +gboolean +rspamd_lru_hash_remove (rspamd_lru_hash_t *hash, + gconstpointer key) +{ + rspamd_lru_element_t *res; + + res = g_hash_table_lookup (hash->tbl, key); + + if (res != NULL) { + rspamd_lru_hash_remove_node (hash, res); + + return TRUE; + } + + return FALSE; +} + void rspamd_lru_hash_insert (rspamd_lru_hash_t *hash, gpointer key, gpointer value, time_t now, guint ttl) diff --git a/src/libutil/hash.h b/src/libutil/hash.h index 80bdf8ae3..7638d6397 100644 --- a/src/libutil/hash.h +++ b/src/libutil/hash.h @@ -53,6 +53,15 @@ rspamd_lru_hash_t * rspamd_lru_hash_new_full ( gpointer rspamd_lru_hash_lookup (rspamd_lru_hash_t *hash, gconstpointer key, time_t now); + +/** + * Removes key from LRU cache + * @param hash + * @param key + * @return TRUE if key has been found and removed + */ +gboolean rspamd_lru_hash_remove (rspamd_lru_hash_t *hash, + gconstpointer key); /** * Insert item in hash * @param hash hash object