Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,16 @@ func (c *Cache[K, V]) Metrics() Metrics {
return c.metrics
}

// Cost returns the total cost of all items currently stored in the cache.
// Note: Cost tracking is only active when a maximum cost limit is configured.
// If no maximum cost is set, this method will always return 0.
func (c *Cache[K, V]) Cost() uint64 {
c.items.mu.RLock()
defer c.items.mu.RUnlock()

return c.cost
}
Comment on lines +640 to +648

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably write a simple test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Anhui-tqhuang is this something you can add?


// Start starts an automatic cleanup process that periodically deletes
// expired items.
// It blocks until Stop is called.
Expand Down