1. The problem I’m having:
I want to cache some GET responses for static resources. I notice that the default in-memory cache when using cache_handler plugin with minimal configuration only allows me to store entires that are up to 1MB in size. How can I configure it to store a small number of very large files (say up to 500MB) that will be downloaded often by clients. I don’t want to keep hitting backend servers for the same file and am happy to hold them in memory. My current configuration is working fine for files smaller than 1MB and the 24 hours TTL seems to be fine. So how can I support larger files?
2. Error messages and/or full log output:
{"level":"debug","ts":1723035465.317409,"logger":"http.handlers.cache","msg":"Incomming request &{Method:GET URL:/storage/blob/download/865EFE98955C70CC36869A6A73509D08DBECFDFA Proto:HTTP/2.0 ProtoMajor:2 ProtoMinor:0 Header:map[Accept:[text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7] Accept-Encoding:[gzip, deflate, br, zstd] Accept-Language:[en-US,en;q=0.9] Cache-Control:[max-age=0] Cookie:[REDACTED] Priority:[u=0, i] Sec-Ch-Ua:[\"Not)A;Brand\";v=\"99\", \"Google Chrome\";v=\"127\", \"Chromium\";v=\"127\"] Sec-Ch-Ua-Mobile:[?0] Sec-Ch-Ua-Platform:[\"Windows\"] Sec-Fetch-Dest:[document] Sec-Fetch-Mode:[navigate] Sec-Fetch-Site:[none] Sec-Fetch-User:[?1] Upgrade-Insecure-Requests:[1] User-Agent:[Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36]] Body:0xc00048e888 GetBody:<nil> ContentLength:0 TransferEncoding:[] Close:false Host:gateway.test.com Form:map[] PostForm:map[] MultipartForm:<nil> Trailer:map[] RemoteAddr:192.168.1.116:52363 RequestURI:/storage/blob/download/865EFE98955C70CC36869A6A73509D08DBECFDFA TLS:0xc000259d90 Cancel:<nil> Response:<nil> ctx:0xc0006b8a20 pat:<nil> matches:[] otherValues:map[]}"}
{"level":"debug","ts":1723035465.317409,"logger":"http.handlers.cache","msg":"Request cache-control &{MaxAge:0 MaxStale:-1 MaxStaleSet:false MinFresh:-1 NoCache:false NoStore:false NoTransform:false OnlyIfCached:false StaleIfError:0 Extensions:[]}"}
{"level":"debug","ts":1723035465.317409,"logger":"http.handlers.cache","msg":"Request the upstream server"}
{"level":"debug","ts":1723035465.317409,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"backend.test.com:443","total_upstreams":1}
{"level":"debug","ts":1723035465.317409,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"backend.test.com:443","duration":0,"request":{"remote_ip":"192.168.1.116","remote_port":"52363","client_ip":"192.168.1.116","proto":"HTTP/2.0","method":"GET","host":"gateway.test.com","uri":"/storage/blob/download/865EFE98955C70CC36869A6A73509D08DBECFDFA","headers":{"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Site":["none"],"Accept-Encoding":["gzip, deflate, br, zstd"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-User":["?1"],"X-Forwarded-Host":["gateway.test.com"],"Priority":["u=0, i"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Date":["Wed, 07 Aug 2024 12:57:45 UTC"],"Accept-Language":["en-US,en;q=0.9"],"Cookie":[REDACTED],"Cache-Control":["max-age=0"],"X-Forwarded-For":["192.168.1.116"],"X-Forwarded-Proto":["https"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"],"Sec-Fetch-Dest":["document"],"Sec-Fetch-Mode":["navigate"],"Sec-Ch-Ua":["\"Not)A;Brand\";v=\"99\", \"Google Chrome\";v=\"127\", \"Chromium\";v=\"127\""],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"gateway.test.com"}},"headers":{"Date":["Wed, 07 Aug 2024 12:32:51 GMT"],"Age":["1494"],"Cache-Control":["public, s-maxage=86400"],"Content-Length":["27822080"],"Content-Disposition":["attachment; filename=gotham_v1.27.7.bin"],"X-Frame-Options":["SAMEORIGIN"],"Content-Security-Policy":["frame-ancestors 'self'"]},"status":200}
{"level":"debug","ts":1723035465.6802907,"logger":"http.handlers.cache","msg":"Response cache-control &{MustRevalidate:false NoCache:map[] NoCachePresent:false NoStore:false NoTransform:false Public:true Private:map[] PrivatePresent:false ProxyRevalidate:false MaxAge:-1 SMaxAge:86400 Immutable:false StaleIfError:-1 StaleWhileRevalidate:-1 Extensions:[]}"}
{"level":"debug","ts":1723035465.7239394,"logger":"http.handlers.cache","msg":"Store the response for GET-https-gateway.test.com-/storage/blob/download/865EFE98955C70CC36869A6A73509D08DBECFDFA with duration 23h59m59.3197092s"}
{"level":"error","ts":1723035465.8361752,"logger":"http.handlers.cache","msg":"Impossible to set the key GET-https-gateway.test.com-/storage/blob/download/865EFE98955C70CC36869A6A73509D08DBECFDFA into Badger, Value with size 16085847 exceeded 1048576 limit. Value:\n00000000 04 22 4d 18 64 70 b9 90 19 30 00 f6 70 48 54 54 |.\"M.dp...0..pHTT|\n00000010 50 2f 30 2e 30 20 32 30 30 20 4f 4b 0d 0a 41 67 |P/0.0 200 OK..Ag|\n00000020 65 3a 20 31 34 39 34 0d 0a 43 61 63 68 65 2d 43 |e: 1494..Cache-C|\n00000030 6f 6e 74 72 6f 6c 3a 20 70 75 62 6c 69 63 2c 20 |ontrol: public, |\n00000040 73 2d 6d 61 78 61 67 65 3d 38 36 34 30 30 0d 0a |s-maxage=86400..|\n00000050 43 6f 6e 74 65 6e 74 2d 44 69 73 70 6f 73 69 74 |Content-Disposit|\n00000060 69 6f 6e 3a 20 61 74 74 61 63 68 6d 65 6e 74 3b |ion: attachment;|\n00000070 20 66 69 6c 65 6e 61 6d 65 3d 67 6f 74 68 61 6d | filename=gotham|\n00000080 5f 76 31 2e 32 37 2e 37 2e 62 69 6e 3e 00 fd 8a |_v1.27.7.bin>...|\n00000090 53 65 63 75 72 69 74 79 2d 50 6f 6c 69 63 79 3a |Security-Policy:|\n000000a0 20 66 72 61 6d 65 2d 61 6e 63 65 73 74 6f 72 73 | frame-ancestors|\n000000b0 20 27 73 65 6c 66 27 0d 0a 44 61 74 65 3a 20 57 | 'self'..Date: W|\n000000c0 65 64 2c 20 30 37 20 41 75 67 20 32 30 32 34 20 |ed, 07 Aug 2024 |\n000000d0 31 32 3a 33 32 3a 35 31 20 47 4d 54 0d 0a 53 65 |12:32:51 GMT..Se|\n000000e0 72 76 65 72 3a 20 43 61 64 64 79 0d 0a 58 2d 46 |rver: Caddy..X-F|\n000000f0 72 61 6d 65 2d 4f 70 74 69 6f 6e 73 3a 20 53 41 |rame-Options: SA|\n00000100 4d 45 4f 52 49 47 49 4e 0d 0a 58 2d 53 6f 75 69 |MEORIGIN..X-Soui|\n00000110 6e 2d 53 74 6f 72 65 64 2d 4c 65 6e 67 74 68 3a |n-Stored-Length:|\n00000120 20 32 37 38 32 32 30 38 30 21 00 f3 19 54 74 6c | 27822080!...Ttl|\n00000130 3a 20 32 34 68 30 6d 30 73 0d 0a 0d 0a 00 08 00 |: 24h0m0s.......|\n00000140 00 00 00 00 00 00 18 00 00 00 08 02 00 00 30 03 |..............0.|\n00000150 00 00 58 74 00 16 00 02 02 00 73 f0 f2 00 00 08 |..Xt......s.....|\n00000160 67 01 0e 00 0f 02 00 3b 12 11 4e 00 f2 01 18 02 |g......;..N.....|\n00000170 02 00 60 2b 03 00 04 51 74 00 04 e9 f2 00 16 00 |..`+...Qt.......|\n00000180 03 02 00 6f 01 67 01 00 81 a8 80 00 42 42 bd 9f |...o.g......BB..|\n00000190 21 33 04 01 17 04 04 00 13 90 04 00 08 02 00 53 |!3.............S|\n000001a0 a0 00 00 00 48 10 00 13 90 08 00 52 00 00 00 00 |....H......R....|\n000001b0 60 07 00 23 00 00 40 00 04 51 01 0f 02 00 17 2e |`..#..@..Q......|\n000001c0 e8 03 04 00 0f 02 00 01 53 6a 02 00 00 18 ab 01 |........Sj......|\n000001d0 04 08 00 0f 02 00 01 08 28 00 13 05 04 00 0f 02 |........(.......|\n000001e0 00 01 17 10 04 00 0f 02 00 09 ff 1e 72 74 73 70 |............rtsp|\n000001f0 5f 61 75 74 6f 73 74 6f 70 3d 64 69 73 61 62 6c |_autostop=disabl|\n00000200 65 20 73 65 63 5f 73 74 72 65 61 6d 5f 73 69 7a |e sec_stream_siz|\n00000210 65 3d 37 32 30 78 34 30 30 48 00 08 0f 02 00 ff |e=720x400H......|\n00000220 ff ff ff ff 86 c2 89 10 be 3d 03 00 01 00 0f 06 |.........=......|\n00000230 e7 07 08 07 af 00 00 01 00 00 00 90 eb 24 a3 71 |.............$.q|\n00000240 07 42 0f 02 00 7c f5 3a cb 00 00 ea 61 37 6c 00 |.B...|.:....a7l.|\n00000250 00 00 00 00 43 4b 03 00 d4 30 00 00 95 01 08 00 |....CK...0......|\n00000260 a3 48 b8 48 7a 56 ff 01 a3 00 00 00 88 13 00 00 |.H.HzV..........|\n00000270 01 00 3f 01 21 15 00 01 02 00 01 01 00 00 02 01 |..?.!...........|\n00000280 00 00 03 01 02 00 03 01 40 00 00 00 31 00 02 00 |........@...1...|\n00000290 26 68 07 95 10 1b 00 00 71 3f 00 83 06 e9 00 22 |&h......q?.....\"|\n000002a0 20 20 04 00 a2 31 45 07 00 31 45 07 00 11 3b 04 | ...1E..1E...;.|\n000002b0 00 d2 00 00 e5 12 00 01 00 00 02 00 00 00 e4 2e |................|\n000002c0 00 93 c0 00 00 00 00 00 e0 00 70 9b 07 04 02 00 |..........p.....|\n000002d0 23 c0 00 60 00 13 11 19 00 22 03 00 38 00 9f 00 |#..`.....\"..8...|\n000002e0 01 28 05 01 00 00 00 20 01 00 04 83 00 00 01 c0 |.(..... ........|\n000002f0 78 56 34 12 48 00 23 00 50 08 00 04 02 00 f2 ff |xV4.H.#.P.......|\n00000300 3c 01 00 00 00 07 00 00 00 00 11 11 12 f2 46 6d |<.............Fm|\n00000310 48 85 46 20 98 00 28 1a d0 6b 48 06 68 04 25 2e |H.F ..(..kH.h.%.|\n00000320 40 21 98 22 9a d1 43 01 23 c3 62 83 69 0b 40 83 |@!.\"..C.#.b.i.@.|\n00000330 61 83 6a 13 43 83 62 43 68 13 43 43 60 03 68 0b |a.j.C.bCh.CC`.h.|\n00000340 40 00 2e 00 d1 13 43 03 60 00 23 db 43 43 62 5f |@.....C.`.#.CCb_|\n00000350 4b 01 3b 00 2b fc d1 5e 48 36 9f 07 60 5d 4d 37 |K.;.+..^H6..`]M7|\n00000360 9e 38 9f 00 f0 d5 f8 10 99 dc 22 a9 50 11 99 5a |.8........\".P..Z|\n00000370 4a a9 50 12 99 59 4a a9 50 10 99 01 23 19 43 dc |J.P..YJ.P...#.C.|\n00000380 22 a9 50 db 43 19 40 a9 50 26 99 00 29 05 d0 54 |\".P.C.@.P&..)..T|\n00000390 4a 54 49 a9 50 50 22 54 49 a9 50 13 99 90 22 a9 |JTI.PP\"TI.P...\".|\n000003a0 50 14 99 94 22 a9 50 15 99 f0 22 a9 50 16 99 f4 |P...\".P...\".P...|\n000003b0 22 a9 50 17 99 4d 4a a9 50 18 99 4d 4a a9 50 19 |\".P..MJ.P..MJ.P.|\n000003c0 99 4c 4a a9 50 1a 99 4c 4a a9 50 1b 99 4b 4a a9 |.LJ.P..LJ.P..KJ.|\n000003d0 50 2c 22 20 23 00 21 4a 4a a9 50 3e 4d 6e 6b 80 |P,\" #.!JJ.P>Mnk.|\n000003e0 21 0e 40 f6 09 47 4d 01 21 69 60 00 21 69 60 38 |!.@..GM.!i`.!i`8|\n000003f0 48 05 99 00 f0 8f f8 1f 99 c1 62 01 99 41 60 02 |H.........b..A`.|\n"}
{"level":"error","ts":1723035465.8361752,"logger":"http.handlers.cache","msg":"Impossible to set value into Badger, Value with size 16085847 exceeded 1048576 limit. Value:\n00000000 04 22 4d 18 64 70 b9 90 19 30 00 f6 70 48 54 54 |.\"M.dp...0..pHTT|\n00000010 50 2f 30 2e 30 20 32 30 30 20 4f 4b 0d 0a 41 67 |P/0.0 200 OK..Ag|\n00000020 65 3a 20 31 34 39 34 0d 0a 43 61 63 68 65 2d 43 |e: 1494..Cache-C|\n00000030 6f 6e 74 72 6f 6c 3a 20 70 75 62 6c 69 63 2c 20 |ontrol: public, |\n00000040 73 2d 6d 61 78 61 67 65 3d 38 36 34 30 30 0d 0a |s-maxage=86400..|\n00000050 43 6f 6e 74 65 6e 74 2d 44 69 73 70 6f 73 69 74 |Content-Disposit|\n00000060 69 6f 6e 3a 20 61 74 74 61 63 68 6d 65 6e 74 3b |ion: attachment;|\n00000070 20 66 69 6c 65 6e 61 6d 65 3d 67 6f 74 68 61 6d | filename=gotham|\n00000080 5f 76 31 2e 32 37 2e 37 2e 62 69 6e 3e 00 fd 8a |_v1.27.7.bin>...|\n00000090 53 65 63 75 72 69 74 79 2d 50 6f 6c 69 63 79 3a |Security-Policy:|\n000000a0 20 66 72 61 6d 65 2d 61 6e 63 65 73 74 6f 72 73 | frame-ancestors|\n000000b0 20 27 73 65 6c 66 27 0d 0a 44 61 74 65 3a 20 57 | 'self'..Date: W|\n000000c0 65 64 2c 20 30 37 20 41 75 67 20 32 30 32 34 20 |ed, 07 Aug 2024 |\n000000d0 31 32 3a 33 32 3a 35 31 20 47 4d 54 0d 0a 53 65 |12:32:51 GMT..Se|\n000000e0 72 76 65 72 3a 20 43 61 64 64 79 0d 0a 58 2d 46 |rver: Caddy..X-F|\n000000f0 72 61 6d 65 2d 4f 70 74 69 6f 6e 73 3a 20 53 41 |rame-Options: SA|\n00000100 4d 45 4f 52 49 47 49 4e 0d 0a 58 2d 53 6f 75 69 |MEORIGIN..X-Soui|\n00000110 6e 2d 53 74 6f 72 65 64 2d 4c 65 6e 67 74 68 3a |n-Stored-Length:|\n00000120 20 32 37 38 32 32 30 38 30 21 00 f3 19 54 74 6c | 27822080!...Ttl|\n00000130 3a 20 32 34 68 30 6d 30 73 0d 0a 0d 0a 00 08 00 |: 24h0m0s.......|\n00000140 00 00 00 00 00 00 18 00 00 00 08 02 00 00 30 03 |..............0.|\n00000150 00 00 58 74 00 16 00 02 02 00 73 f0 f2 00 00 08 |..Xt......s.....|\n00000160 67 01 0e 00 0f 02 00 3b 12 11 4e 00 f2 01 18 02 |g......;..N.....|\n00000170 02 00 60 2b 03 00 04 51 74 00 04 e9 f2 00 16 00 |..`+...Qt.......|\n00000180 03 02 00 6f 01 67 01 00 81 a8 80 00 42 42 bd 9f |...o.g......BB..|\n00000190 21 33 04 01 17 04 04 00 13 90 04 00 08 02 00 53 |!3.............S|\n000001a0 a0 00 00 00 48 10 00 13 90 08 00 52 00 00 00 00 |....H......R....|\n000001b0 60 07 00 23 00 00 40 00 04 51 01 0f 02 00 17 2e |`..#..@..Q......|\n000001c0 e8 03 04 00 0f 02 00 01 53 6a 02 00 00 18 ab 01 |........Sj......|\n000001d0 04 08 00 0f 02 00 01 08 28 00 13 05 04 00 0f 02 |........(.......|\n000001e0 00 01 17 10 04 00 0f 02 00 09 ff 1e 72 74 73 70 |............rtsp|\n000001f0 5f 61 75 74 6f 73 74 6f 70 3d 64 69 73 61 62 6c |_autostop=disabl|\n00000200 65 20 73 65 63 5f 73 74 72 65 61 6d 5f 73 69 7a |e sec_stream_siz|\n00000210 65 3d 37 32 30 78 34 30 30 48 00 08 0f 02 00 ff |e=720x400H......|\n00000220 ff ff ff ff 86 c2 89 10 be 3d 03 00 01 00 0f 06 |.........=......|\n00000230 e7 07 08 07 af 00 00 01 00 00 00 90 eb 24 a3 71 |.............$.q|\n00000240 07 42 0f 02 00 7c f5 3a cb 00 00 ea 61 37 6c 00 |.B...|.:....a7l.|\n00000250 00 00 00 00 43 4b 03 00 d4 30 00 00 95 01 08 00 |....CK...0......|\n00000260 a3 48 b8 48 7a 56 ff 01 a3 00 00 00 88 13 00 00 |.H.HzV..........|\n00000270 01 00 3f 01 21 15 00 01 02 00 01 01 00 00 02 01 |..?.!...........|\n00000280 00 00 03 01 02 00 03 01 40 00 00 00 31 00 02 00 |........@...1...|\n00000290 26 68 07 95 10 1b 00 00 71 3f 00 83 06 e9 00 22 |&h......q?.....\"|\n000002a0 20 20 04 00 a2 31 45 07 00 31 45 07 00 11 3b 04 | ...1E..1E...;.|\n000002b0 00 d2 00 00 e5 12 00 01 00 00 02 00 00 00 e4 2e |................|\n000002c0 00 93 c0 00 00 00 00 00 e0 00 70 9b 07 04 02 00 |..........p.....|\n000002d0 23 c0 00 60 00 13 11 19 00 22 03 00 38 00 9f 00 |#..`.....\"..8...|\n000002e0 01 28 05 01 00 00 00 20 01 00 04 83 00 00 01 c0 |.(..... ........|\n000002f0 78 56 34 12 48 00 23 00 50 08 00 04 02 00 f2 ff |xV4.H.#.P.......|\n00000300 3c 01 00 00 00 07 00 00 00 00 11 11 12 f2 46 6d |<.............Fm|\n00000310 48 85 46 20 98 00 28 1a d0 6b 48 06 68 04 25 2e |H.F ..(..kH.h.%.|\n00000320 40 21 98 22 9a d1 43 01 23 c3 62 83 69 0b 40 83 |@!.\"..C.#.b.i.@.|\n00000330 61 83 6a 13 43 83 62 43 68 13 43 43 60 03 68 0b |a.j.C.bCh.CC`.h.|\n00000340 40 00 2e 00 d1 13 43 03 60 00 23 db 43 43 62 5f |@.....C.`.#.CCb_|\n00000350 4b 01 3b 00 2b fc d1 5e 48 36 9f 07 60 5d 4d 37 |K.;.+..^H6..`]M7|\n00000360 9e 38 9f 00 f0 d5 f8 10 99 dc 22 a9 50 11 99 5a |.8........\".P..Z|\n00000370 4a a9 50 12 99 59 4a a9 50 10 99 01 23 19 43 dc |J.P..YJ.P...#.C.|\n00000380 22 a9 50 db 43 19 40 a9 50 26 99 00 29 05 d0 54 |\".P.C.@.P&..)..T|\n00000390 4a 54 49 a9 50 50 22 54 49 a9 50 13 99 90 22 a9 |JTI.PP\"TI.P...\".|\n000003a0 50 14 99 94 22 a9 50 15 99 f0 22 a9 50 16 99 f4 |P...\".P...\".P...|\n000003b0 22 a9 50 17 99 4d 4a a9 50 18 99 4d 4a a9 50 19 |\".P..MJ.P..MJ.P.|\n000003c0 99 4c 4a a9 50 1a 99 4c 4a a9 50 1b 99 4b 4a a9 |.LJ.P..LJ.P..KJ.|\n000003d0 50 2c 22 20 23 00 21 4a 4a a9 50 3e 4d 6e 6b 80 |P,\" #.!JJ.P>Mnk.|\n000003e0 21 0e 40 f6 09 47 4d 01 21 69 60 00 21 69 60 38 |!.@..GM.!i`.!i`8|\n000003f0 48 05 99 00 f0 8f f8 1f 99 c1 62 01 99 41 60 02 |H.........b..A`.|\n"}
3. Caddy version:
v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=
4. How I installed and ran Caddy:
a. System environment:
Windows 11 with Caddy running natively.
b. Command:
caddy_windows_amd64_custom.exe run
c. Service/unit/compose file:
N/A
d. My complete Caddy config:
{
cache
}
:443 {
# Use your own wildcard certificate with relative paths
tls ./certs/certificate.crt ./certs/privatekey.key
@devicefirmware path *storage/blob/download/*
cache @devicefirmware {
ttl 86400s
}
reverse_proxy {
to https://backend.test.com
# Load Balancing
lb_policy least_conn
# Active Health checks
health_uri /ping
health_interval 30s
}
}