MCPcopy Create free account
hub / github.com/ericls/imgdd / put

Method put

httpserver/image_response_cache.go:77–102  ·  view source on GitHub ↗
(key string, contentType string, etag string, xImgddSI string, body []byte)

Source from the content-addressed store, hash-verified

75}
76
77func (c *imageResponseCache) put(key string, contentType string, etag string, xImgddSI string, body []byte) {
78 if c == nil || int64(len(body)) > c.maxFileBytes {
79 return
80 }
81 c.mu.Lock()
82 defer c.mu.Unlock()
83
84 if existing, ok := c.items.Get(key); ok {
85 c.currentBytes -= int64(len(existing.body))
86 }
87 entry := &imageResponseCacheEntry{
88 key: key,
89 contentType: contentType,
90 etag: etag,
91 xImgddSI: xImgddSI,
92 body: append([]byte(nil), body...),
93 }
94 c.items.Add(key, entry)
95 c.currentBytes += int64(len(entry.body))
96
97 for c.currentBytes > c.maxBytes {
98 if _, _, ok := c.items.RemoveOldest(); !ok {
99 break
100 }
101 }
102}
103
104func writeCachedImageResponse(w http.ResponseWriter, r *http.Request, entry *imageResponseCacheEntry) {
105 if r.Header.Get("If-None-Match") == entry.etag {

Calls 1

GetMethod · 0.65