summaryrefslogtreecommitdiff
path: root/src/caches/dcache_add.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/caches/dcache_add.c')
-rw-r--r--src/caches/dcache_add.c28
1 files changed, 2 insertions, 26 deletions
diff --git a/src/caches/dcache_add.c b/src/caches/dcache_add.c
index bbe5fea..b69b1ca 100644
--- a/src/caches/dcache_add.c
+++ b/src/caches/dcache_add.c
@@ -12,9 +12,7 @@
#include <skalibs/avltree.h>
#include <s6-dns/dcache.h>
-
-#define DNODE(z, i) GENSETDYN_P(dcache_node_t, &(z)->storage, i)
-#define DCACHE_NODE_OVERHEAD (32 + sizeof(dcache_node_t) + 3 * sizeof(avlnode))
+#include "dcache-internal.h"
static void uniquify (avltree const *tree, tain_t *stamp)
{
@@ -24,17 +22,6 @@ static void uniquify (avltree const *tree, tain_t *stamp)
tain_add(stamp, stamp, &nano) ;
}
-static void dcache_delete (dcache_t *z, uint32_t i)
-{
- dcache_node_t *y = DNODE(z, i) ;
- avltree_delete(&z->by_expire, &y->expire) ;
- avltree_delete(&z->by_entry, &y->entry) ;
- avltree_delete(&z->by_key, &y->key) ;
- alloc_free(y->key.s) ;
- z->size -= DCACHE_NODE_OVERHEAD + y->key.len + y->datalen ;
- gensetdyn_delete(&z->storage, i) ;
-}
-
static inline void dcache_gc_by_entry (dcache_t *z, uint64_t max)
{
while (z->size > max)
@@ -45,17 +32,6 @@ static inline void dcache_gc_by_entry (dcache_t *z, uint64_t max)
}
}
-static inline void dcache_gc_by_expire (dcache_t *z, tain_t const *stamp)
-{
- for (;;)
- {
- uint32_t i ;
- if (!avltree_min(&z->by_expire, &i)) break ;
- if (tain_less(stamp, &DNODE(z, i)->expire)) break ;
- dcache_delete(z, i) ;
- }
-}
-
static inline int dcache_add_node (dcache_t *z, dcache_node_t const *node)
{
uint32_t i ;
@@ -104,7 +80,7 @@ int dcache_add (dcache_t *z, uint64_t max, char const *key, uint16_t keylen, cha
{
uint64_t size = DCACHE_NODE_OVERHEAD + keylen + datalen ;
if (size > max) return (errno = EINVAL, 0) ;
- if (z->size > max - size) dcache_gc_by_expire(z, stamp) ;
+ if (z->size > max - size) dcache_clean_expired(z, stamp) ;
if (z->size > max - size) dcache_gc_by_entry(z, max - size) ;
return dcache_add_unbounded(z, key, keylen, data, datalen, expire, stamp) ;
}