Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions models/actions/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ type ActionTask struct {
Updated timeutil.TimeStamp `xorm:"updated index"`
}

var successfulTokenTaskCache *lru.Cache
var successfulTokenTaskCache *lru.Cache[string, any]

func init() {
db.RegisterModel(new(ActionTask), func() error {
if setting.SuccessfulTokensCacheSize > 0 {
var err error
successfulTokenTaskCache, err = lru.New(setting.SuccessfulTokensCacheSize)
successfulTokenTaskCache, err = lru.New[string, any](setting.SuccessfulTokensCacheSize)
if err != nil {
return fmt.Errorf("unable to allocate Task cache: %v", err)
}
Expand Down
10 changes: 5 additions & 5 deletions models/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (err ErrAccessTokenEmpty) Unwrap() error {
return util.ErrInvalidArgument
}

var successfulAccessTokenCache *lru.Cache
var successfulAccessTokenCache *lru.Cache[string, any]

// AccessToken represents a personal access token.
type AccessToken struct {
Expand Down Expand Up @@ -83,7 +83,7 @@ func init() {
db.RegisterModel(new(AccessToken), func() error {
if setting.SuccessfulTokensCacheSize > 0 {
var err error
successfulAccessTokenCache, err = lru.New(setting.SuccessfulTokensCacheSize)
successfulAccessTokenCache, err = lru.New[string, any](setting.SuccessfulTokensCacheSize)
if err != nil {
return fmt.Errorf("unable to allocate AccessToken cache: %w", err)
}
Expand Down Expand Up @@ -154,16 +154,16 @@ func GetAccessTokenBySHA(token string) (*AccessToken, error) {
lastEight := token[len(token)-8:]

if id := getAccessTokenIDFromCache(token); id > 0 {
token := &AccessToken{
accessToken := &AccessToken{
TokenLastEight: lastEight,
}
// Re-get the token from the db in case it has been deleted in the intervening period
has, err := db.GetEngine(db.DefaultContext).ID(id).Get(token)
has, err := db.GetEngine(db.DefaultContext).ID(id).Get(accessToken)
if err != nil {
return nil, err
}
if has {
return token, nil
return accessToken, nil
}
successfulAccessTokenCache.Remove(token)
}
Expand Down
10 changes: 5 additions & 5 deletions modules/cache/cache_twoqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// TwoQueueCache represents a LRU 2Q cache adapter implementation
type TwoQueueCache struct {
lock sync.Mutex
cache *lru.TwoQueueCache
cache *lru.TwoQueueCache[string, any]
interval int
}

Expand Down Expand Up @@ -146,7 +146,7 @@ func (c *TwoQueueCache) Flush() error {
return nil
}

func (c *TwoQueueCache) checkAndInvalidate(key any) {
func (c *TwoQueueCache) checkAndInvalidate(key string) {
c.lock.Lock()
defer c.lock.Unlock()
cached, ok := c.cache.Peek(key)
Expand All @@ -155,7 +155,7 @@ func (c *TwoQueueCache) checkAndInvalidate(key any) {
}
item, ok := cached.(*MemoryItem)
if !ok || item.hasExpired() {
c.cache.Remove(item)
c.cache.Remove(key)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think key should be used when removing from cache.

}
}

Expand Down Expand Up @@ -187,9 +187,9 @@ func (c *TwoQueueCache) StartAndGC(opts mc.Options) error {
GhostRatio: lru.Default2QGhostEntries,
}
_ = json.Unmarshal([]byte(opts.AdapterConfig), cfg)
c.cache, err = lru.New2QParams(cfg.Size, cfg.RecentRatio, cfg.GhostRatio)
c.cache, err = lru.New2QParams[string, any](cfg.Size, cfg.RecentRatio, cfg.GhostRatio)
} else {
c.cache, err = lru.New2Q(size)
c.cache, err = lru.New2Q[string, any](size)
}
c.interval = opts.Interval
if c.interval > 0 {
Expand Down
4 changes: 2 additions & 2 deletions modules/highlight/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (

once sync.Once

cache *lru.TwoQueueCache
cache *lru.TwoQueueCache[string, any]

githubStyles = styles.Get("github")
)
Expand All @@ -46,7 +46,7 @@ func NewContext() {
highlightMapping = setting.GetHighlightMapping()

// The size 512 is simply a conservative rule of thumb
c, err := lru.New2Q(512)
c, err := lru.New2Q[string, any](512)
if err != nil {
panic(fmt.Sprintf("failed to initialize LRU cache for highlighter: %s", err))
}
Expand Down
4 changes: 2 additions & 2 deletions modules/regexplru/regexplru.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
lru "github.com/hashicorp/golang-lru/v2"
)

var lruCache *lru.Cache
var lruCache *lru.Cache[string, any]

func init() {
var err error
lruCache, err = lru.New(1000)
lruCache, err = lru.New[string, any](1000)
if err != nil {
log.Fatal("failed to new LRU cache, err: %v", err)
}
Expand Down