]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Limit the number of entries in the cache. Closes #156
authorAlan T. DeKok <aland@freeradius.org>
Wed, 6 Feb 2013 18:07:13 +0000 (13:07 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 6 Feb 2013 18:07:13 +0000 (13:07 -0500)
src/modules/rlm_cache/rlm_cache.c

index 8d572841b767b2fcea730ca5b84b878d3c71dd60..92afe4117ada324dbf3b1c7a5cfc88a200e158cb 100644 (file)
@@ -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,