Start modernizing the cache a bit.
This commit is contained in:
17
src/cache.cc
17
src/cache.cc
@ -46,7 +46,10 @@
|
|||||||
* Local data types
|
* Local data types
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct {
|
struct CacheEntry_t
|
||||||
|
{
|
||||||
|
~CacheEntry_t();
|
||||||
|
|
||||||
const DilloUrl *Url; /**< Cached Url. Url is used as a primary Key */
|
const DilloUrl *Url; /**< Cached Url. Url is used as a primary Key */
|
||||||
char *TypeDet; /**< MIME type string (detected from data) */
|
char *TypeDet; /**< MIME type string (detected from data) */
|
||||||
char *TypeHdr; /**< MIME type string as from the HTTP Header */
|
char *TypeHdr; /**< MIME type string as from the HTTP Header */
|
||||||
@ -64,7 +67,7 @@ typedef struct {
|
|||||||
int ExpectedSize; /**< Goal size of the HTTP transfer (0 if unknown)*/
|
int ExpectedSize; /**< Goal size of the HTTP transfer (0 if unknown)*/
|
||||||
int TransferSize; /**< Actual length of the HTTP transfer */
|
int TransferSize; /**< Actual length of the HTTP transfer */
|
||||||
uint_t Flags; /**< See Flag Defines in cache.h */
|
uint_t Flags; /**< See Flag Defines in cache.h */
|
||||||
} CacheEntry_t;
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -254,7 +257,7 @@ static CacheEntry_t *Cache_entry_add(const DilloUrl *Url)
|
|||||||
dList_remove(CachedURLs, old_entry);
|
dList_remove(CachedURLs, old_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
new_entry = dNew(CacheEntry_t, 1);
|
new_entry = new CacheEntry_t{};
|
||||||
Cache_entry_init(new_entry, Url); /* Set safe values */
|
Cache_entry_init(new_entry, Url); /* Set safe values */
|
||||||
dList_insert_sorted(CachedURLs, new_entry, Cache_entry_cmp);
|
dList_insert_sorted(CachedURLs, new_entry, Cache_entry_cmp);
|
||||||
return new_entry;
|
return new_entry;
|
||||||
@ -294,8 +297,9 @@ static void Cache_auth_free(Dlist *auth)
|
|||||||
/**
|
/**
|
||||||
* Free the components of a CacheEntry_t struct.
|
* Free the components of a CacheEntry_t struct.
|
||||||
*/
|
*/
|
||||||
static void Cache_entry_free(CacheEntry_t *entry)
|
CacheEntry_t::~CacheEntry_t()
|
||||||
{
|
{
|
||||||
|
auto *const entry= this;
|
||||||
delete const_cast< DilloUrl * >( entry->Url );
|
delete const_cast< DilloUrl * >( entry->Url );
|
||||||
dFree(entry->TypeDet);
|
dFree(entry->TypeDet);
|
||||||
dFree(entry->TypeHdr);
|
dFree(entry->TypeHdr);
|
||||||
@ -312,7 +316,6 @@ static void Cache_entry_free(CacheEntry_t *entry)
|
|||||||
a_Decode_transfer_free(entry->TransferDecoder);
|
a_Decode_transfer_free(entry->TransferDecoder);
|
||||||
if (entry->ContentDecoder)
|
if (entry->ContentDecoder)
|
||||||
a_Decode_free(entry->ContentDecoder);
|
a_Decode_free(entry->ContentDecoder);
|
||||||
dFree(entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -346,7 +349,7 @@ static void Cache_entry_remove(CacheEntry_t *entry, DilloUrl *url)
|
|||||||
|
|
||||||
/* remove from cache */
|
/* remove from cache */
|
||||||
dList_remove(CachedURLs, entry);
|
dList_remove(CachedURLs, entry);
|
||||||
Cache_entry_free(entry);
|
delete entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1451,7 +1454,7 @@ void a_Cache_freeall(void)
|
|||||||
/* Remove every cache entry */
|
/* Remove every cache entry */
|
||||||
while ((data = dList_nth_data(CachedURLs, 0))) {
|
while ((data = dList_nth_data(CachedURLs, 0))) {
|
||||||
dList_remove_fast(CachedURLs, data);
|
dList_remove_fast(CachedURLs, data);
|
||||||
Cache_entry_free(reinterpret_cast< CacheEntry_t * >( data ));
|
delete reinterpret_cast< CacheEntry_t * >( data );
|
||||||
}
|
}
|
||||||
/* Remove the cache list */
|
/* Remove the cache list */
|
||||||
dList_free(CachedURLs);
|
dList_free(CachedURLs);
|
||||||
|
|||||||
Reference in New Issue
Block a user