From: Alan T. DeKok Date: Wed, 6 Feb 2013 18:07:13 +0000 (-0500) Subject: Limit the number of entries in the cache. Closes #156 X-Git-Tag: release_2_2_1~183 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=837e3c726d1126190872718df9650ca23d38b12f;p=thirdparty%2Ffreeradius-server.git Limit the number of entries in the cache. Closes #156 --- diff --git a/src/modules/rlm_cache/rlm_cache.c b/src/modules/rlm_cache/rlm_cache.c index 8d572841b76..92afe4117ad 100644 --- a/src/modules/rlm_cache/rlm_cache.c +++ b/src/modules/rlm_cache/rlm_cache.c @@ -41,6 +41,7 @@ typedef struct rlm_cache_t { int ttl; int epoch; int stats; + int max_entries; CONF_SECTION *cs; rbtree_t *cache; fr_heap_t *heap; @@ -230,6 +231,11 @@ static rlm_cache_entry_t *cache_add(rlm_cache_t *inst, REQUEST *request, rlm_cache_entry_t *c; char buffer[1024]; + if (rbtree_num_elements(inst->cache) >= inst->max_entries) { + RDEBUG("Cache is full: %d entries", inst->max_entries); + return NULL; + } + /* * TTL of 0 means "don't cache this entry" */ @@ -438,6 +444,8 @@ static const CONF_PARSER module_config[] = { offsetof(rlm_cache_t, key), NULL, NULL}, { "ttl", PW_TYPE_INTEGER, offsetof(rlm_cache_t, ttl), NULL, "500" }, + { "max_entries", PW_TYPE_INTEGER, + offsetof(rlm_cache_t, max_entries), NULL, "16384" }, { "epoch", PW_TYPE_INTEGER, offsetof(rlm_cache_t, epoch), NULL, "0" }, { "add-stats", PW_TYPE_BOOLEAN,