Get 获取缓存
(key string)
| 606 | |
| 607 | // Get 获取缓存 |
| 608 | func (c *CompressionCache) Get(key string) *CompressResult { |
| 609 | c.mu.RLock() |
| 610 | defer c.mu.RUnlock() |
| 611 | |
| 612 | if result, ok := c.cache[key]; ok { |
| 613 | // 返回副本 |
| 614 | return &CompressResult{ |
| 615 | Compressed: result.Compressed, |
| 616 | OriginalLength: result.OriginalLength, |
| 617 | CompressedLength: result.CompressedLength, |
| 618 | CompressionRatio: result.CompressionRatio, |
| 619 | TokensSaved: result.TokensSaved, |
| 620 | Duration: result.Duration, |
| 621 | Mode: result.Mode, |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | return nil |
| 626 | } |
| 627 | |
| 628 | // Set 设置缓存 |
| 629 | func (c *CompressionCache) Set(key string, result *CompressResult) { |
no outgoing calls