1 Star 0 Fork 0

kzangv/gsf-fof

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
negative_cache.go 806 Bytes
Copy Edit Raw Blame History
kzangv authored 2023-02-23 10:22 . fixed
package cache
import (
"fmt"
"time"
)
type _TimeoutItem struct {
_DurationItem
use bool
}
func (c *_TimeoutItem) Next(t time.Time) *time.Time {
if c.use {
c.use = false
c.val, c.err = c.get()
return c.sch.Next(t)
}
return nil
}
func (c *_TimeoutItem) setUse() {
c.use = true
}
type TimeoutCache struct {
Cache
}
func (c *TimeoutCache) Add(name string, sec int, get PullHandle) {
e := &_TimeoutItem{
_DurationItem: _DurationItem{
get: get,
sch: c.handle(sec),
},
use: true,
}
c.cron.AddScheduleJob(NegativeTimeoutPrefix+name, e)
}
func (c *TimeoutCache) Get(name string) (interface{}, error) {
sj := c.cron.Job(NegativeTimeoutPrefix + name)
if sj == nil {
return nil, fmt.Errorf("key [%s] is no find", name)
}
j := sj.(*_TimeoutItem)
j.setUse()
return j.Value()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kzangv/gsf-fof.git
git@gitee.com:kzangv/gsf-fof.git
kzangv
gsf-fof
gsf-fof
v0.4.3

Search