From a11dc034b469bc73427b7978b6546575fc65e879 Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Wed, 6 Feb 2013 13:07:13 -0500 Subject: [PATCH] Limit the number of entries in the cache. Closes #156 --- src/modules/rlm_cache/rlm_cache.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/modules/rlm_cache/rlm_cache.c b/src/modules/rlm_cache/rlm_cache.c index 215f11b7b862..9636e4886726 100644 --- a/src/modules/rlm_cache/rlm_cache.c +++ b/src/modules/rlm_cache/rlm_cache.c @@ -39,6 +39,7 @@ typedef struct rlm_cache_t { const char *xlat_name; char *key; int ttl; + int max_entries; int epoch; int stats; CONF_SECTION *cs; @@ -272,6 +273,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" */ @@ -694,6 +700,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,