Files
tasks/common/cache/size_getter.go
Stephan BehnkeandGitHub c9e360a3fb go fix (#9337)
## What changed?

Integrate Go 1.26's new `go fix` into workflow.

NOTE that the changes caused our linter to fire; a [separate
commit](https://github.com/temporalio/temporal/pull/9337/commits/1b23f787aef370098b35829c4d17dcc06230b4c1)
addresses those.

## Why?

Ensure Go code is standardized/modernized.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)
2026-02-18 09:12:19 -08:00

23 lines
825 B
Go

//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination size_getter_mock.go
package cache
// SizeGetter is an interface that can be implemented by cache entries to provide their size.
// Cache uses CacheSize() to determine the size of a cache entry.
// Please be aware that if the size of the cache entry changes while the cache is being used without pinning enabled,
// the cache won't be able to automatically adjust for this size change. In such instances, it's necessary to call Put()
// again to ensure the cache size remains accurate.
type (
SizeGetter interface {
CacheSize() int
}
)
func getSize(value any) int {
if v, ok := value.(SizeGetter); ok {
return v.CacheSize()
}
// if the object does not have a CacheSize() method, assume is count limit cache, which size should be 1
return 1
}