parseCache parses c returns the specified Cache implementation.
(c string)
| 132 | |
| 133 | // parseCache parses c returns the specified Cache implementation. |
| 134 | func parseCache(c string) (imageproxy.Cache, error) { |
| 135 | const defaultMemorySize = 100 |
| 136 | |
| 137 | if c == "" { |
| 138 | return nil, nil |
| 139 | } |
| 140 | |
| 141 | if c == "memory" { |
| 142 | c = fmt.Sprintf("memory:%d", defaultMemorySize) |
| 143 | } |
| 144 | |
| 145 | u, err := url.Parse(c) |
| 146 | if err != nil { |
| 147 | return nil, fmt.Errorf("error parsing cache flag: %w", err) |
| 148 | } |
| 149 | |
| 150 | switch u.Scheme { |
| 151 | case "file": |
| 152 | return diskCache(u.Path), nil |
| 153 | default: |
| 154 | return diskCache(c), nil |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | func diskCache(path string) *diskcache.Cache { |
| 159 | d := diskv.New(diskv.Options{ |