[dovecot-cvs] dovecot/src/auth auth-cache.c,1.9,1.10

cras at dovecot.org cras at dovecot.org
Sat Mar 5 13:57:32 EET 2005


Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv7699

Modified Files:
	auth-cache.c 
Log Message:
auth_cache_insert(): Don't remove expired nodes just because they're
expired. Before inserting a node, make sure it doesn't already exist (expired).



Index: auth-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-cache.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- auth-cache.c	28 Feb 2005 22:41:33 -0000	1.9
+++ auth-cache.c	5 Mar 2005 11:57:29 -0000	1.10
@@ -167,12 +167,9 @@
 		       const char *key, const char *value)
 {
 	string_t *str;
-	time_t now, ttl_time;
         struct cache_node *node;
 	size_t data_size, alloc_size, value_len = strlen(value);
 
-	now = time(NULL);
-
 	str = t_str_new(256);
 	var_expand(str, key,
 		   auth_request_get_var_expand_table(request, str_escape));
@@ -180,19 +177,19 @@
 	data_size = str_len(str) + 1 + value_len + 1;
 	alloc_size = sizeof(struct cache_node) - sizeof(node->data) + data_size;
 
-	ttl_time = now - cache->ttl_secs;
-	while (cache->tail != NULL && cache->tail->created < ttl_time) {
-		/* TTL expired, destroy */
-		auth_cache_node_destroy(cache, cache->tail);
-	}
-
 	/* make sure we have enough space */
 	while (cache->size_left < alloc_size)
 		auth_cache_node_destroy(cache, cache->tail);
 
+	node = hash_lookup(cache->hash, str_c(str));
+	if (node != NULL) {
+		/* key is already in cache (probably expired), remove it */
+		auth_cache_node_destroy(cache, node);
+	}
+
 	/* @UNSAFE */
 	node = i_malloc(alloc_size);
-	node->created = now;
+	node->created = time(NULL);
 	node->alloc_size = alloc_size;
 	memcpy(node->data, str_data(str), str_len(str));
 	memcpy(node->data + str_len(str) + 1, value, value_len);



More information about the dovecot-cvs mailing list