MCPcopy
hub / github.com/willnorris/imageproxy / parseCache

Function parseCache

caddy/module.go:134–156  ·  view source on GitHub ↗

parseCache parses c returns the specified Cache implementation.

(c string)

Source from the content-addressed store, hash-verified

132
133// parseCache parses c returns the specified Cache implementation.
134func 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
158func diskCache(path string) *diskcache.Cache {
159 d := diskv.New(diskv.Options{

Callers 1

ProvisionMethod · 0.70

Calls 1

diskCacheFunction · 0.70

Tested by

no test coverage detected