package imagegen import ( "sync" "time" ) // cache 效果图 URL 缓存(key: 方案内容 hash:角度,24h TTL) type cache struct { mu sync.Mutex items map[string]cacheEntry } type cacheEntry struct { url string expiresAt time.Time } var effectCache = &cache{items: make(map[string]cacheEntry)} // CacheGet 读取缓存 URL func CacheGet(key string) (string, bool) { return cacheGet(key) } // CacheSet 写入缓存 URL func CacheSet(key, url string) { cacheSet(key, url) } func cacheGet(key string) (string, bool) { effectCache.mu.Lock() defer effectCache.mu.Unlock() e, ok := effectCache.items[key] if !ok { return "", false } if time.Now().After(e.expiresAt) { delete(effectCache.items, key) return "", false } return e.url, true } func cacheSet(key, url string) { effectCache.mu.Lock() defer effectCache.mu.Unlock() effectCache.items[key] = cacheEntry{url: url, expiresAt: time.Now().Add(24 * time.Hour)} }