mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-30 14:56:19 +00:00
## What changed? This adds support to the lru cache to actively expire entries older than the TTL, by spawning a background goroutine that periodically deletes old entries. A dynamic config, off by default, is added that can enable this feature for the workflow cache. ## Why? This can reduce the memory usage, and associated Go GC resource usage, for workflow entries that won't be utilized since they are past their TTL. ## How did you test it? - [x] built - [x] run locally and tested manually - [x] covered by existing tests - [x] added new unit test(s) - [ ] added new functional test(s) Also running this in test setups to verify expected memory reduction. ## Potential risks
26 lines
333 B
Go
26 lines
333 B
Go
package cache
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
var Module = fx.Options(
|
|
fx.Provide(NewHostLevelCache),
|
|
fx.Invoke(func(
|
|
lc fx.Lifecycle,
|
|
cache Cache,
|
|
) {
|
|
lc.Append(fx.Hook{
|
|
OnStop: func(_ context.Context) error {
|
|
ci, ok := cache.(*cacheImpl)
|
|
if ok {
|
|
ci.stop()
|
|
}
|
|
return nil
|
|
},
|
|
})
|
|
}),
|
|
)
|