MCPcopy
hub / github.com/daptin/daptin / CalculateExpiry

Function CalculateExpiry

server/cache/file_cache.go:127–158  ·  view source on GitHub ↗

CalculateExpiry determines expiry time based on file type

(mimeType, path string)

Source from the content-addressed store, hash-verified

125
126// CalculateExpiry determines expiry time based on file type
127func CalculateExpiry(mimeType, path string) time.Time {
128 now := time.Now()
129
130 // Determine file type from extension
131 filename := filepath.Base(path)
132 ext := strings.ToLower(filepath.Ext(filename))
133
134 // Images
135 if strings.HasPrefix(mimeType, "image/") ||
136 ext == ".jpg" || ext == ".jpeg" || ext == ".png" ||
137 ext == ".gif" || ext == ".webp" || ext == ".svg" {
138 return now.Add(ImageCacheExpiry)
139 }
140
141 // Text files
142 if strings.HasPrefix(mimeType, "text/") ||
143 strings.Contains(mimeType, "javascript") ||
144 strings.Contains(mimeType, "json") ||
145 ext == ".html" || ext == ".css" || ext == ".js" ||
146 ext == ".txt" || ext == ".md" || ext == ".xml" {
147 return now.Add(TextCacheExpiry)
148 }
149
150 // Video files
151 if strings.HasPrefix(mimeType, "video/") ||
152 ext == ".mp4" || ext == ".webm" || ext == ".ogg" {
153 return now.Add(VideoCacheExpiry)
154 }
155
156 // Default for other files
157 return now.Add(DefaultCacheExpiry)
158}
159
160func GenerateETag(content []byte, modTime time.Time) string {
161 hash := md5.New()

Callers 3

AssetRouteHandlerFunction · 0.92
SetMethod · 0.85

Calls 1

AddMethod · 0.80

Tested by

no test coverage detected