mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-05 00:20:27 +08:00
[waf]支持包含二进制、不支持二进制等操作符;支持对参数值编解码
This commit is contained in:
57
internal/cache/piece.go
vendored
Normal file
57
internal/cache/piece.go
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Piece struct {
|
||||
m map[uint64]*Item
|
||||
locker sync.RWMutex
|
||||
}
|
||||
|
||||
func NewPiece() *Piece {
|
||||
return &Piece{m: map[uint64]*Item{}}
|
||||
}
|
||||
|
||||
func (this *Piece) Add(key uint64, item *Item) () {
|
||||
this.locker.Lock()
|
||||
this.m[key] = item
|
||||
this.locker.Unlock()
|
||||
}
|
||||
|
||||
func (this *Piece) Delete(key uint64) {
|
||||
this.locker.Lock()
|
||||
delete(this.m, key)
|
||||
this.locker.Unlock()
|
||||
}
|
||||
|
||||
func (this *Piece) Read(key uint64) (item *Item) {
|
||||
this.locker.RLock()
|
||||
item = this.m[key]
|
||||
if item != nil && item.expiredAt < utils.UnixTime() {
|
||||
item = nil
|
||||
}
|
||||
this.locker.RUnlock()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Piece) Count() (count int) {
|
||||
this.locker.RLock()
|
||||
count = len(this.m)
|
||||
this.locker.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Piece) GC() {
|
||||
this.locker.Lock()
|
||||
timestamp := time.Now().Unix()
|
||||
for k, item := range this.m {
|
||||
if item.expiredAt <= timestamp {
|
||||
delete(this.m, k)
|
||||
}
|
||||
}
|
||||
this.locker.Unlock()
|
||||
}
|
||||
Reference in New Issue
Block a user