mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 12:12:35 +03:00
Implement hlcache_poll(), which drives the low-level cache event loop, and attempts to clean the high-level cache.
Call this, instead of llcache_poll(). svn path=/trunk/netsurf/; revision=10371
This commit is contained in:
parent
7dcc15cbd4
commit
71de3618f1
@ -73,6 +73,7 @@ static hlcache_entry *hlcache_content_list;
|
||||
/** Ring of retrieval contexts */
|
||||
static hlcache_retrieval_ctx *hlcache_retrieval_ctx_ring;
|
||||
|
||||
static void hlcache_clean(void);
|
||||
static nserror hlcache_llcache_callback(llcache_handle *handle,
|
||||
const llcache_event *event, void *pw);
|
||||
static bool hlcache_type_is_acceptable(llcache_handle *llcache,
|
||||
@ -86,6 +87,17 @@ static void hlcache_content_callback(struct content *c,
|
||||
* Public API *
|
||||
******************************************************************************/
|
||||
|
||||
/* See hlcache.h for documentation */
|
||||
nserror hlcache_poll(void)
|
||||
{
|
||||
llcache_poll();
|
||||
|
||||
/* Give the cache a clean */
|
||||
hlcache_clean();
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
/* See hlcache.h for documentation */
|
||||
nserror hlcache_handle_retrieve(const char *url, uint32_t flags,
|
||||
const char *referer, llcache_post_data *post,
|
||||
@ -266,6 +278,46 @@ nserror hlcache_handle_abort(hlcache_handle *handle)
|
||||
* High-level cache internals *
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* Attempt to clean the cache
|
||||
*/
|
||||
void hlcache_clean(void)
|
||||
{
|
||||
hlcache_entry *entry, *next;
|
||||
|
||||
for (entry = hlcache_content_list; entry != NULL; entry = next) {
|
||||
next = entry->next;
|
||||
|
||||
if (entry->content == NULL)
|
||||
continue;
|
||||
|
||||
if (content_count_users(entry->content) != 0)
|
||||
continue;
|
||||
|
||||
/** \todo This is over-zealous: all unused contents will be
|
||||
* immediately destroyed. Ideally, we want to purge all
|
||||
* unused contents that are using stale source data, and
|
||||
* enough fresh contents such that the cache fits in the
|
||||
* configured cache size limit.
|
||||
*/
|
||||
|
||||
/* Remove entry from cache */
|
||||
if (entry->prev == NULL)
|
||||
hlcache_content_list = entry->next;
|
||||
else
|
||||
entry->prev->next = entry->next;
|
||||
|
||||
if (entry->next != NULL)
|
||||
entry->next->prev = entry->prev;
|
||||
|
||||
/* Destroy content */
|
||||
content_destroy(entry->content);
|
||||
|
||||
/* Destroy entry */
|
||||
free(entry);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for low-level cache events
|
||||
*
|
||||
|
@ -63,6 +63,14 @@ enum hlcache_retrieve_flag {
|
||||
HLCACHE_RETRIEVE_MAY_DOWNLOAD = (1 << 31)
|
||||
};
|
||||
|
||||
/**
|
||||
* Drive the low-level cache poll loop, and attempt to clean the cache.
|
||||
* No guarantee is made about what, if any, cache cleaning will occur.
|
||||
*
|
||||
* \return NSERROR_OK
|
||||
*/
|
||||
nserror hlcache_poll(void);
|
||||
|
||||
/**
|
||||
* Retrieve a high-level cache handle for an object
|
||||
*
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "utils/config.h"
|
||||
#include "utils/utsname.h"
|
||||
#include "content/fetch.h"
|
||||
#include "content/llcache.h"
|
||||
#include "content/hlcache.h"
|
||||
#include "content/urldb.h"
|
||||
#include "desktop/netsurf.h"
|
||||
#include "desktop/browser.h"
|
||||
@ -136,7 +136,7 @@ int netsurf_main_loop(void)
|
||||
{
|
||||
while (!netsurf_quit) {
|
||||
gui_poll(fetch_active);
|
||||
llcache_poll();
|
||||
hlcache_poll();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user