MCPcopy
hub / github.com/fish2018/pansou / Get

Method Get

util/cache/disk_cache.go:173–208  ·  view source on GitHub ↗

Get 获取缓存

(key string)

Source from the content-addressed store, hash-verified

171
172// Get 获取缓存
173func (c *DiskCache) Get(key string) ([]byte, bool, error) {
174 c.mutex.RLock()
175 meta, exists := c.metadata[key]
176 c.mutex.RUnlock()
177
178 if !exists {
179 return nil, false, nil
180 }
181
182 // 检查是否过期
183 if time.Now().After(meta.Expiry) {
184 c.Delete(key)
185 return nil, false, nil
186 }
187
188 // 获取文件路径
189 filePath := filepath.Join(c.path, c.getFilename(key))
190
191 // 读取文件
192 data, err := ioutil.ReadFile(filePath)
193 if err != nil {
194 // 如果文件不存在,删除元数据
195 if os.IsNotExist(err) {
196 c.Delete(key)
197 }
198 return nil, false, err
199 }
200
201 // 更新最后使用时间
202 c.mutex.Lock()
203 meta.LastUsed = time.Now()
204 c.saveMetadata(key, meta)
205 c.mutex.Unlock()
206
207 return data, true, nil
208}
209
210// Delete 删除缓存
211func (c *DiskCache) Delete(key string) error {

Callers 15

searchImplMethod · 0.45
fetchDetailPageLinksMethod · 0.45
searchPageMethod · 0.45
doLoginMethod · 0.45
searchWithScraperMethod · 0.45
fetchDetailMethod · 0.45
keepAllSessionsAliveMethod · 0.45
searchImplMethod · 0.45
getResponseReaderMethod · 0.45
getSearchIDMethod · 0.45

Calls 3

DeleteMethod · 0.95
getFilenameMethod · 0.95
saveMetadataMethod · 0.95

Tested by

no test coverage detected