del cache cleanup items limit
This commit is contained in:
parent
0db1564012
commit
b434b8a455
@ -129,19 +129,17 @@ func (a *App) Run(p RunParams) {
|
|||||||
|
|
||||||
// Periodically trigger cache cleanup
|
// Periodically trigger cache cleanup
|
||||||
go func() {
|
go func() {
|
||||||
tmr := time.NewTicker(5 * time.Minute)
|
tmr := time.NewTicker(15 * time.Minute)
|
||||||
defer tmr.Stop()
|
defer tmr.Stop()
|
||||||
|
|
||||||
batchSize := 100
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case <-tmr.C:
|
case <-tmr.C:
|
||||||
userCache.CheckExpired(batchSize)
|
userCache.CheckExpired()
|
||||||
jwtCache.CheckExpired(batchSize)
|
jwtCache.CheckExpired()
|
||||||
linksCache.CheckExpired(batchSize)
|
linksCache.CheckExpired()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
7
pkg/cache/cache_inmem.go
vendored
7
pkg/cache/cache_inmem.go
vendored
@ -78,7 +78,7 @@ func (c *cacheInmem[K, V]) Del(key K) {
|
|||||||
delete(c.data, key)
|
delete(c.data, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cacheInmem[K, V]) CheckExpired(batchSize int) {
|
func (c *cacheInmem[K, V]) CheckExpired() {
|
||||||
if len(c.data) == 0 {
|
if len(c.data) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -90,10 +90,5 @@ func (c *cacheInmem[K, V]) CheckExpired(batchSize int) {
|
|||||||
if time.Now().After(item.Expiration) {
|
if time.Now().After(item.Expiration) {
|
||||||
delete(c.data, key)
|
delete(c.data, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
batchSize--
|
|
||||||
if batchSize <= 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
pkg/cache/cache_inmem_sharded.go
vendored
5
pkg/cache/cache_inmem_sharded.go
vendored
@ -45,10 +45,9 @@ func (c *cacheInmemSharded[V]) Del(key string) {
|
|||||||
c.getShard(key).Del(key)
|
c.getShard(key).Del(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cacheInmemSharded[V]) CheckExpired(batchSize int) {
|
func (c *cacheInmemSharded[V]) CheckExpired() {
|
||||||
size := batchSize / c.info.Shards
|
|
||||||
for _, shard := range c.shards {
|
for _, shard := range c.shards {
|
||||||
shard.CheckExpired(size)
|
shard.CheckExpired()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
pkg/cache/interface.go
vendored
2
pkg/cache/interface.go
vendored
@ -7,5 +7,5 @@ type Cache[K comparable, V any] interface {
|
|||||||
Set(key K, value V, exp Expiration)
|
Set(key K, value V, exp Expiration)
|
||||||
|
|
||||||
Del(key K)
|
Del(key K)
|
||||||
CheckExpired(batchSize int)
|
CheckExpired()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user