From e0a95886077f474ff180eb89f4f20a7b406ea24e Mon Sep 17 00:00:00 2001 From: Will Norris Date: Fri, 21 Nov 2014 07:48:24 -0800 Subject: [PATCH] add cacheSize flag to cmd/imageproxy httpcache hardcodes the cache size to 100MB. We are still using that as the default value, but it can now be overridden. refs #9 --- cmd/imageproxy/main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/imageproxy/main.go b/cmd/imageproxy/main.go index d365eb3..8ee260a 100644 --- a/cmd/imageproxy/main.go +++ b/cmd/imageproxy/main.go @@ -24,6 +24,7 @@ import ( "github.com/gregjones/httpcache" "github.com/gregjones/httpcache/diskcache" + "github.com/peterbourgon/diskv" "willnorris.com/go/imageproxy" ) @@ -39,6 +40,7 @@ var ( 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") +var cacheSize = flag.Uint64("cacheSize", 100, "maximum size of file cache (in MB)") var version = flag.Bool("version", false, "print version information") func main() { @@ -51,7 +53,11 @@ func main() { var c httpcache.Cache if *cacheDir != "" { - c = diskcache.New(*cacheDir) + d := diskv.New(diskv.Options{ + BasePath: *cacheDir, + CacheSizeMax: *cacheSize * 1024 * 1024, + }) + c = diskcache.NewWithDiskv(d) } else { c = httpcache.NewMemoryCache() }