mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-12 02:45:49 +02:00
feat: 2FA authorization for web terminal
This commit is contained in:
parent
802d05f692
commit
3a22861640
15 changed files with 359 additions and 54 deletions
31
internal/cache/cache.go
vendored
Normal file
31
internal/cache/cache.go
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
package cache
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/dgraph-io/ristretto"
|
||||
"time"
|
||||
)
|
||||
|
||||
var cache *ristretto.Cache
|
||||
|
||||
func Init() {
|
||||
var err error
|
||||
cache, err = ristretto.NewCache(&ristretto.Config{
|
||||
NumCounters: 1e7, // number of keys to track frequency of (10M).
|
||||
MaxCost: 1 << 30, // maximum cost of cache (1GB).
|
||||
BufferItems: 64, // number of keys per Get buffer.
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
logger.Fatal("initializing local cache err", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Set(key interface{}, value interface{}, ttl time.Duration) {
|
||||
cache.SetWithTTL(key, value, 0, ttl)
|
||||
cache.Wait()
|
||||
}
|
||||
|
||||
func Get(key interface{}) (value interface{}, ok bool) {
|
||||
return cache.Get(key)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue