0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2024-12-16 21:56:43 -05:00

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
This commit is contained in:
Will Norris 2014-11-21 07:48:24 -08:00
parent 7994cb2cf6
commit e0a9588607

View file

@ -24,6 +24,7 @@ import (
"github.com/gregjones/httpcache" "github.com/gregjones/httpcache"
"github.com/gregjones/httpcache/diskcache" "github.com/gregjones/httpcache/diskcache"
"github.com/peterbourgon/diskv"
"willnorris.com/go/imageproxy" "willnorris.com/go/imageproxy"
) )
@ -39,6 +40,7 @@ var (
var addr = flag.String("addr", "localhost:8080", "TCP address to listen on") 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 whitelist = flag.String("whitelist", "", "comma separated list of allowed remote hosts")
var cacheDir = flag.String("cacheDir", "", "directory to use for file cache") 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") var version = flag.Bool("version", false, "print version information")
func main() { func main() {
@ -51,7 +53,11 @@ func main() {
var c httpcache.Cache var c httpcache.Cache
if *cacheDir != "" { if *cacheDir != "" {
c = diskcache.New(*cacheDir) d := diskv.New(diskv.Options{
BasePath: *cacheDir,
CacheSizeMax: *cacheSize * 1024 * 1024,
})
c = diskcache.NewWithDiskv(d)
} else { } else {
c = httpcache.NewMemoryCache() c = httpcache.NewMemoryCache()
} }