From fe437a0b8c6109c9d6b7fa46f8d33eb4e3d83aba Mon Sep 17 00:00:00 2001 From: Will Norris Date: Sun, 9 Jun 2019 22:09:55 +0000 Subject: [PATCH] allow specifying multiple cache with spaces this is necessary for the new environment variable support for config values. I don't love that allowHosts is comma separated and cache is space separated :( --- README.md | 10 +++++----- cmd/imageproxy/main.go | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2c0ae91..faa8d5e 100644 --- a/README.md +++ b/README.md @@ -160,11 +160,11 @@ version. [codercat URL]: http://localhost:8080/500/https://octodex.github.com/images/codercat.jpg -If the `-cache` flag is specified multiple times, multiple caches will be -created in a [tiered fashion][]. Typically this is used to put a smaller and -faster in-memory cache in front of a larger but slower on-disk cache. For -example, the following will first check an in-memory cache for an image, -followed by a gcs bucket: +Multiple caches can be specified by separating them by spaces or by repeating +the `-cache` flag multiple times. The caches will be created in a [tiered +fashion][]. Typically this is used to put a smaller and faster in-memory cache +in front of a larger but slower on-disk cache. For example, the following will +first check an in-memory cache for an image, followed by a gcs bucket: imageproxy -cache memory -cache gcs://my-bucket/ diff --git a/cmd/imageproxy/main.go b/cmd/imageproxy/main.go index 6ea1095..4b10b24 100644 --- a/cmd/imageproxy/main.go +++ b/cmd/imageproxy/main.go @@ -122,15 +122,17 @@ func (tc *tieredCache) String() string { } func (tc *tieredCache) Set(value string) error { - c, err := parseCache(value) - if err != nil { - return err - } + for _, v := range strings.Fields(value) { + c, err := parseCache(v) + if err != nil { + return err + } - if tc.Cache == nil { - tc.Cache = c - } else { - tc.Cache = twotier.New(tc.Cache, c) + if tc.Cache == nil { + tc.Cache = c + } else { + tc.Cache = twotier.New(tc.Cache, c) + } } return nil }