Commit 45d44a63 by Philipp Schafft

Feature: Clear XSLT cache on config reload

parent 3ffe5f4e
Pipeline #245 failed with stage
in 11 seconds
......@@ -44,6 +44,7 @@
#include "connection.h"
#include "main.h"
#include "slave.h"
#include "xslt.h"
#define CATMODULE "CONFIG"
#define CONFIG_DEFAULT_LOCATION "Earth"
......@@ -748,6 +749,7 @@ void config_reread_config(void)
stats_global(config);
config_release_config();
slave_update_all_mounts();
xslt_clear_cache();
}
}
......
......@@ -115,14 +115,8 @@ void xslt_initialize(void)
}
void xslt_shutdown(void) {
int i;
for(i=0; i < CACHESIZE; i++) {
if(cache[i].filename)
free(cache[i].filename);
if(cache[i].stylesheet)
xsltFreeStylesheet(cache[i].stylesheet);
}
xslt_clear_cache();
thread_mutex_destroy (&xsltlock);
xmlCleanupParser();
......@@ -131,6 +125,26 @@ void xslt_shutdown(void) {
xmlFree(admin_path);
}
static void clear_cache_entry(size_t idx) {
free(cache[idx].filename);
if (cache[idx].stylesheet)
xsltFreeStylesheet(cache[idx].stylesheet);
}
void xslt_clear_cache(void)
{
size_t i;
ICECAST_LOG_DEBUG("Clearing stylesheet cache.");
thread_mutex_lock(&xsltlock);
for (i = 0; i < CACHESIZE; i++)
clear_cache_entry(i);
thread_mutex_unlock(&xsltlock);
}
static int evict_cache_entry(void) {
int i, age=0, oldest=0;
......@@ -141,8 +155,7 @@ static int evict_cache_entry(void) {
}
}
xsltFreeStylesheet(cache[oldest].stylesheet);
free(cache[oldest].filename);
clear_cache_entry(oldest);
return oldest;
}
......@@ -282,9 +295,11 @@ static xmlDocPtr custom_loader(const xmlChar *URI,
/* Get the actual xmlDoc */
if (final_URI) {
ICECAST_LOG_DEBUG("Calling xslt_loader() for \"%s\" (was: \"%s\").", final_URI, URI);
ret = xslt_loader(final_URI, dict, options, ctxt, type);
xmlFree(final_URI);
} else {
ICECAST_LOG_DEBUG("Calling xslt_loader() for \"%s\".", URI);
ret = xslt_loader(URI, dict, options, ctxt, type);
}
return ret;
......
......@@ -19,4 +19,5 @@
void xslt_transform(xmlDocPtr doc, const char *xslfilename, client_t *client, int status);
void xslt_initialize(void);
void xslt_shutdown(void);
void xslt_clear_cache(void);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment