mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-28 08:26:35 +08:00
优化代码:使用fasttime取代以往的utils.UnixTime
This commit is contained in:
@@ -2,6 +2,7 @@ package ttlcache
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -74,7 +75,7 @@ func (this *Cache) Write(key string, value interface{}, expiredAt int64) (ok boo
|
||||
return
|
||||
}
|
||||
|
||||
var currentTimestamp = utils.UnixTime()
|
||||
var currentTimestamp = fasttime.Now().Unix()
|
||||
if expiredAt <= currentTimestamp {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package ttlcache
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"github.com/iwind/TeaGo/rands"
|
||||
@@ -195,7 +195,7 @@ func BenchmarkCache_Add(b *testing.B) {
|
||||
|
||||
var cache = NewCache()
|
||||
for i := 0; i < b.N; i++ {
|
||||
cache.Write(strconv.Itoa(i), i, utils.UnixTime()+int64(i%1024))
|
||||
cache.Write(strconv.Itoa(i), i, fasttime.Now().Unix()+int64(i%1024))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ func BenchmarkCache_Add_Parallel(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
var j = atomic.AddInt64(&i, 1)
|
||||
cache.Write(types.String(j), j, utils.UnixTime()+i%1024)
|
||||
cache.Write(types.String(j), j, fasttime.Now().Unix()+i%1024)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package ttlcache
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/expires"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -75,7 +75,7 @@ func (this *Piece) Delete(key uint64) {
|
||||
func (this *Piece) Read(key uint64) (item *Item) {
|
||||
this.locker.RLock()
|
||||
item = this.m[key]
|
||||
if item != nil && item.expiredAt < utils.UnixTime() {
|
||||
if item != nil && item.expiredAt < fasttime.Now().Unix() {
|
||||
item = nil
|
||||
}
|
||||
this.locker.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user