Skip to content

Commit 5d26f00

Browse files
authored
Merge pull request #27 from flownative/persistent-resource-cache
TASK: Enable persistent resources caching
2 parents 9d702f3 + bc6ea7c commit 5d26f00

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

root-files/build.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ useradd --home-dir "${NGINX_BASE_PATH}" --no-create-home --no-user-group --uid 1
88
groupadd --gid 1000 nginx
99

1010
mkdir -p \
11-
"${NGINX_BASE_PATH}/cache" \
11+
"${NGINX_BASE_PATH}/cache/application" \
12+
"${NGINX_BASE_PATH}/cache/resources" \
1213
"${NGINX_BASE_PATH}/etc" \
1314
"${NGINX_BASE_PATH}/modules" \
1415
"${NGINX_BASE_PATH}/sbin" \

root-files/opt/flownative/lib/nginx-legacy.sh

+8
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ EOM
243243
${addHeaderStrictTransportSecurity}
244244
proxy_pass ${BEACH_ASSET_PROXY_ENDPOINT}/\$1\$is_args\$args?reqid=\$request_id;
245245
expires ${NGINX_STATIC_FILES_LIFETIME};
246+
proxy_cache persistent_res;
247+
# we care only about the resource hash as it's the only thing passed on, host is irrelevant
248+
proxy_cache_key \$1;
249+
add_header X-Nginx-Cache-Resources \$upstream_cache_status;
246250
}
247251
EOM
248252
elif [ -n "${BEACH_GOOGLE_CLOUD_STORAGE_PUBLIC_BUCKET}" ]; then
@@ -260,6 +264,10 @@ EOM
260264
${addHeaderStrictTransportSecurity}
261265
proxy_pass https://storage.googleapis.com/${BEACH_GOOGLE_CLOUD_STORAGE_PUBLIC_BUCKET}/\$1\$is_args\$args?reqid=\$request_id;
262266
expires ${NGINX_STATIC_FILES_LIFETIME};
267+
proxy_cache persistent_res;
268+
# we care only about the resource hash as it's the only thing passed on, host is irrelevant
269+
proxy_cache_key \$1;
270+
add_header X-Nginx-Cache-Resources \$upstream_cache_status;
263271
}
264272
EOM
265273
elif [ -n "${BEACH_PERSISTENT_RESOURCES_FALLBACK_BASE_URI}" ]; then

root-files/opt/flownative/lib/nginx.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export NGINX_ACCESS_LOG_MODE="${NGINX_ACCESS_LOG_MODE:-dynamic}"
3030
export NGINX_ACCESS_LOG_FORMAT="${NGINX_ACCESS_LOG_FORMAT:-default}"
3131
export NGINX_ACCESS_LOG_IGNORED_STATUS_CODES_REGEX="${NGINX_ACCESS_LOG_IGNORED_STATUS_CODES_REGEX:-^[13]}"
3232
33-
export NGINX_CACHE_PATH="${NGINX_CACHE_PATH:-${NGINX_BASE_PATH}/cache}"
33+
export NGINX_CACHE_PATH="${NGINX_CACHE_PATH:-${NGINX_BASE_PATH}/cache/application}"
3434
export NGINX_CACHE_ENABLE="${NGINX_CACHE_ENABLE:-no}"
3535
export NGINX_CACHE_NAME="${NGINX_CACHE_NAME:-application}"
3636
export NGINX_CACHE_DEFAULT_LIFETIME="${NGINX_CACHE_DEFAULT_LIFETIME:-5s}"
@@ -39,6 +39,8 @@ export NGINX_CACHE_INACTIVE="${NGINX_CACHE_INACTIVE:-1h}"
3939
export NGINX_CACHE_USE_STALE_OPTIONS="${NGINX_CACHE_USE_STALE_OPTIONS:-updating error timeout invalid_header}"
4040
export NGINX_CACHE_BACKGROUND_UPDATE="${NGINX_CACHE_BACKGROUND_UPDATE:-off}"
4141
42+
export NGINX_CACHE_RESOURCES_PATH="${NGINX_CACHE_PATH:-${NGINX_BASE_PATH}/cache/resources}"
43+
4244
export NGINX_CUSTOM_ERROR_PAGE_CODES="${NGINX_CUSTOM_ERROR_PAGE_CODES:-500 501 502 503}"
4345
export NGINX_CUSTOM_ERROR_PAGE_TARGET="${NGINX_CUSTOM_ERROR_PAGE_TARGET:-}"
4446

root-files/opt/flownative/nginx/etc/nginx.conf.template

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ http {
1919
scgi_temp_path "${NGINX_TMP_PATH}/scgi" 1 2;
2020
uwsgi_temp_path "${NGINX_TMP_PATH}/uwsgi" 1 2;
2121
fastcgi_cache_path "${NGINX_CACHE_PATH}" levels=1:2 keys_zone=application:10m max_size=${NGINX_CACHE_MAX_SIZE};
22+
proxy_cache_path "${NGINX_CACHE_RESOURCES_PATH}" levels=1:2 keys_zone=persistent_res:2m max_size=2g inactive=336h use_temp_path=off;
2223

2324
include ${NGINX_CONF_PATH}/mime.types;
2425
default_type application/octet-stream;

0 commit comments

Comments
 (0)