chore: initial commit
This commit is contained in:
31
internal/pkg/cache/cache.go
vendored
Normal file
31
internal/pkg/cache/cache.go
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"server/internal/db/sqlc"
|
||||
|
||||
"github.com/maypok86/otter/v2"
|
||||
)
|
||||
|
||||
type Caches struct {
|
||||
SysUserApisCache *otter.Cache[int32, []db.GetSysUserApisRow]
|
||||
}
|
||||
|
||||
func NewCaches() *Caches {
|
||||
sysUserApisCache := otter.Must(&otter.Options[int32, []db.GetSysUserApisRow]{
|
||||
MaximumSize: 1_000,
|
||||
})
|
||||
|
||||
return &Caches{
|
||||
SysUserApisCache: sysUserApisCache,
|
||||
}
|
||||
}
|
||||
|
||||
// ClearSysUserCache 清理单个用户缓存
|
||||
func (c *Caches) ClearSysUserCache(userID int32) {
|
||||
c.SysUserApisCache.Invalidate(userID)
|
||||
}
|
||||
|
||||
// ClearAllSysUserCache 清理所有用户缓存
|
||||
func (c *Caches) ClearAllSysUserCache() {
|
||||
c.SysUserApisCache.InvalidateAll()
|
||||
}
|
||||
Reference in New Issue
Block a user