Skip to content

chore: expose cost of cache#196

Open
Anhui-tqhuang wants to merge 1 commit intojellydator:v3from
Anhui-tqhuang:expose-cache-cost
Open

chore: expose cost of cache#196
Anhui-tqhuang wants to merge 1 commit intojellydator:v3from
Anhui-tqhuang:expose-cache-cost

Conversation

@Anhui-tqhuang
Copy link

issue:

currently the cache keeps an internal field named cost

cost uint64

it might be nice to expose it so we don't need to calculate all cost of a cache through loop through all items

@swithek swithek requested review from davseby and swithek October 5, 2025 09:35
Comment on lines +640 to +648
// 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
}
Copy link
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants