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
positive_cache.go 993 Bytes
Copy Edit Raw Blame History
kzangv authored 2023-02-23 10:22 . fixed
package cache
import (
"fmt"
"gitee.com/kzangv/gsf-fof/component/cron/schedule"
"time"
)
type _DurationItem struct {
val interface{}
get PullHandle
err error
sch schedule.Interface
}
func (c *_DurationItem) Init() {}
func (c *_DurationItem) Run(time.Time) {}
func (c *_DurationItem) Destroy() {}
func (c *_DurationItem) Value() (interface{}, error) { return c.val, c.err }
func (c *_DurationItem) Next(t time.Time) *time.Time {
c.val, c.err = c.get()
return c.sch.Next(t)
}
type RefreshCache struct {
Cache
}
func (c *RefreshCache) Add(name string, sec int, get PullHandle) {
e := &_DurationItem{
get: get,
sch: c.handle(sec),
}
c.cron.AddScheduleJob(PositiveDurationPrefix+name, e)
}
func (c *RefreshCache) Get(name string) (interface{}, error) {
sj := c.cron.Job(PositiveDurationPrefix + name)
if sj == nil {
return nil, fmt.Errorf("key [%s] is no find", name)
}
j := sj.(*_DurationItem)
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.2.7

Search