Skip to content

Commit

Permalink
Add cache_free function to cache.c and cache.h
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchen1991 committed Oct 24, 2018
1 parent 6b7caa4 commit 9a5f01f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ struct cache *cache_create(int max_size, int hashsize)
///////////////////
}

void cache_free(struct cache *cache)
{
struct cache_entry *cur_entry = cache->head;

hashtable_destroy(cache->index);

while (cur_entry != NULL) {
struct cache_entry *next_entry = cur_entry->next;

free_entry(cur_entry);

cur_entry = next_entry;
}
}

/**
* Store an entry in the cache
*
Expand Down
1 change: 1 addition & 0 deletions src/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct cache {
extern struct cache_entry *alloc_entry(char *path, char *content_type, void *content, int content_length);
extern void free_entry(struct cache_entry *entry);
extern struct cache *cache_create(int max_size, int hashsize);
extern void cache_free(struct cache *cache);
extern void cache_put(struct cache *cache, char *path, char *content_type, void *content, int content_length);
extern struct cache_entry *cache_get(struct cache *cache, char *path);

Expand Down

0 comments on commit 9a5f01f

Please sign in to comment.