enum rspamd_lru_element_flags {
RSPAMD_LRU_ELEMENT_NORMAL = 0,
RSPAMD_LRU_ELEMENT_VOLATILE = (1 << 0),
+ RSPAMD_LRU_ELEMENT_IMMORTAL = (1 << 1),
};
struct rspamd_lru_element_s {
* or, at some probability scan all table and update eviction
* list first
*/
-
r = rspamd_random_double_fast ();
if (r < ((double)eviction_candidates) / hash->maxsize) {
kh_foreach_value_ptr (hash, cur, {
rspamd_lru_element_t *node = &cur->e;
+ if (node->flags & RSPAMD_LRU_ELEMENT_IMMORTAL) {
+ continue;
+ }
+
if (node->flags & RSPAMD_LRU_ELEMENT_VOLATILE) {
/* If element is expired, just remove it */
if (now - cur->creation_time > cur->ttl) {
node = &vnode->e;
if (ret == 0) {
- /* Existing element, be carefull about destructors */
+ /* Existing element, be careful about destructors */
if (hash->value_destroy) {
/* Remove old data */
hash->value_destroy (vnode->e.data);
if (ret != 0) {
/* Also need to check maxsize */
if (kh_size (hash) >= hash->maxsize) {
+ node->flags |= RSPAMD_LRU_ELEMENT_IMMORTAL;
rspamd_lru_hash_evict (hash, now);
+ node->flags &= ~RSPAMD_LRU_ELEMENT_IMMORTAL;
}
}