Skip to content

Commit

Permalink
rename cache duration, and switch to cleaner time.Add logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jan 26, 2025
1 parent 9499f86 commit 4ac2dec
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions internal/cache/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

var (
CacheDuration = 1 * time.Minute
cleanTaskInterval = CacheDuration / 2
ValidDuration = 1 * time.Minute
cleanTaskInterval = ValidDuration / 2

lastClean time.Time
skippedCleanWithCanvasRefresh = false
Expand All @@ -20,8 +20,8 @@ var (

func init() {
if t, err := time.ParseDuration(os.Getenv("FYNE_CACHE")); err == nil {
CacheDuration = t
cleanTaskInterval = CacheDuration / 2
ValidDuration = t
cleanTaskInterval = ValidDuration / 2
}
}

Expand Down Expand Up @@ -168,5 +168,5 @@ func (c *expiringCache) isExpired(now time.Time) bool {

// setAlive updates expiration time.
func (c *expiringCache) setAlive() {
c.expires = timeNow().Add(CacheDuration)
c.expires = timeNow().Add(ValidDuration)
}
2 changes: 1 addition & 1 deletion internal/cache/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func Test_expiringCache(t *testing.T) {
assert.False(t, c.isExpired(tm.now))

tm.setTime(10, 11)
tm.now = tm.now.Add(CacheDuration)
tm.now = tm.now.Add(ValidDuration)
assert.True(t, c.isExpired(tm.now))
}

Expand Down
2 changes: 1 addition & 1 deletion internal/driver/glfw/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (d *gLDriver) drawSingleFrame() {
// cache alive if it hasn't been done recently
// n.b. we need to make sure threshold is a bit *after*
// time.Now() - CacheDuration()
threshold := time.Now().Add(-cache.CacheDuration).Add(1 * time.Second)
threshold := time.Now().Add(time.Second - cache.ValidDuration)
if w.lastWalked().Before(threshold) {
w.canvas.WalkTrees(nil, func(node *common.RenderCacheNode, _ fyne.Position) {
// marks canvas for widget cache entry alive
Expand Down

0 comments on commit 4ac2dec

Please sign in to comment.