From 1db64563291651e0372b0b3ee6cdd5f3c55d25c4 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Thu, 26 Dec 2013 08:06:00 -0800 Subject: [PATCH] add cacheDir for specifying disk cache dir --- imageproxy.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/imageproxy.go b/imageproxy.go index 8697ee1..64353d9 100644 --- a/imageproxy.go +++ b/imageproxy.go @@ -22,18 +22,26 @@ import ( "strings" "github.com/gregjones/httpcache" + "github.com/gregjones/httpcache/diskcache" "github.com/willnorris/go-imageproxy/proxy" ) var addr = flag.String("addr", "localhost:8080", "TCP address to listen on") var whitelist = flag.String("whitelist", "", "comma separated list of allowed remote hosts") +var cacheDir = flag.String("cacheDir", "", "directory to use for file cache") func main() { flag.Parse() fmt.Printf("go-imageproxy listening on %s\n", *addr) - c := httpcache.NewMemoryCache() + var c httpcache.Cache + if *cacheDir != "" { + c = diskcache.New(*cacheDir) + } else { + c = httpcache.NewMemoryCache() + } + p := proxy.NewProxy(nil, c) p.MaxWidth = 2000 p.MaxHeight = 2000