diff --git a/core/cache.c b/core/cache.c index c3c90e93..6b49e9ae 100644 --- a/core/cache.c +++ b/core/cache.c @@ -200,6 +200,40 @@ static void uwsgi_cache_load_files(struct uwsgi_cache *uc) { next: usl = usl->next; } + +#ifdef UWSGI_ZLIB + usl = uwsgi.load_file_in_cache_gzip; + while(usl) { + size_t len = 0; + char *value = NULL; + char *key = usl->value; + uint16_t key_len = usl->len; + char *space = strchr(usl->value, ' '); + if (space) { + // need to skip ? + if (uwsgi_strncmp(uc->name, uc->name_len, usl->value, space-usl->value)) { + goto next2; + } + key = space+1; + key_len = usl->len - ((space-usl->value)+1); + } + value = uwsgi_open_and_read(key, &len, 0, NULL); + if (value) { + struct uwsgi_buffer *gzipped = uwsgi_gzip(value, len); + if (gzipped) { + uwsgi_wlock(uc->lock); + if (!uwsgi_cache_set2(uc, key, key_len, gzipped->buf, gzipped->len, 0, 0)) { + uwsgi_log("[cache-gzip] stored \"%.*s\" in \"%s\"\n", key_len, key, uc->name); + } + uwsgi_rwunlock(uc->lock); + uwsgi_buffer_destroy(gzipped); + } + free(value); + } +next2: + usl = usl->next; + } +#endif } diff --git a/core/uwsgi.c b/core/uwsgi.c index 9ccc8680..afce0014 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -231,6 +231,9 @@ static struct uwsgi_option uwsgi_base_options[] = { {"cache-use-last-modified", no_argument, 0, "update last_modified_at timestamp on every cache item modification (default is disabled)", uwsgi_opt_true, &uwsgi.cache_use_last_modified, 0}, {"load-file-in-cache", required_argument, 0, "load a static file in the cache", uwsgi_opt_add_string_list, &uwsgi.load_file_in_cache, 0}, +#ifdef UWSGI_ZLIB + {"load-file-in-cache-gzip", required_argument, 0, "load a static file in the cache with gzip compression", uwsgi_opt_add_string_list, &uwsgi.load_file_in_cache_gzip, 0}, +#endif {"cache2", required_argument, 0, "create a new generation shared cache (keyval syntax)", uwsgi_opt_add_string_list, &uwsgi.cache2, 0}, diff --git a/uwsgi.h b/uwsgi.h index 2c485618..d8421862 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2178,6 +2178,9 @@ struct uwsgi_server { size_t rwlock_size; struct uwsgi_string_list *load_file_in_cache; +#ifdef UWSGI_ZLIB + struct uwsgi_string_list *load_file_in_cache_gzip; +#endif char *use_check_cache; struct uwsgi_cache *check_cache; struct uwsgi_cache *caches;