implement nginx caching (#8333)

* implement nginx caching

* bypass cache from frigate frontend, reduce to 5s

* set cache time to 2s

* cache 200s for 5s

* exclude vod endpoints from cache
This commit is contained in:
Blake Blackshear 2023-10-29 07:47:24 -04:00 committed by GitHub
parent cd64399fe5
commit 159fb51518
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -32,6 +32,8 @@ http {
gzip_proxied no-cache no-store private expired auth; gzip_proxied no-cache no-store private expired auth;
gzip_vary on; gzip_vary on;
proxy_cache_path /dev/shm/nginx_cache levels=1:2 keys_zone=api_cache:10m max_size=10m inactive=1m use_temp_path=off;
upstream frigate_api { upstream frigate_api {
server 127.0.0.1:5001; server 127.0.0.1:5001;
keepalive 1024; keepalive 1024;
@ -185,6 +187,19 @@ http {
proxy_pass http://frigate_api/; proxy_pass http://frigate_api/;
include proxy.conf; include proxy.conf;
proxy_cache api_cache;
proxy_cache_lock on;
proxy_cache_use_stale updating;
proxy_cache_valid 200 5s;
proxy_cache_bypass $http_x_cache_bypass;
add_header X-Cache-Status $upstream_cache_status;
location /api/vod/ {
proxy_pass http://frigate_api/vod/;
include proxy.conf;
proxy_cache off;
}
location /api/stats { location /api/stats {
access_log off; access_log off;
rewrite ^/api/(.*)$ $1 break; rewrite ^/api/(.*)$ $1 break;

View File

@ -7,6 +7,7 @@ import axios from 'axios';
axios.defaults.baseURL = `${baseUrl}api/`; axios.defaults.baseURL = `${baseUrl}api/`;
axios.defaults.headers.common = { axios.defaults.headers.common = {
'X-CSRF-TOKEN': 1, 'X-CSRF-TOKEN': 1,
'X-CACHE-BYPASS': 1,
}; };
export function ApiProvider({ children, options }) { export function ApiProvider({ children, options }) {