enhance: proxy settings

This commit is contained in:
Jacky 2024-10-07 11:06:00 +08:00
parent 957d4754f7
commit deda31a6e1
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
15 changed files with 351 additions and 261 deletions

View file

@ -6,11 +6,11 @@ import (
"time"
)
var cache *ristretto.Cache
var cache *ristretto.Cache[string, any]
func Init() {
var err error
cache, err = ristretto.NewCache(&ristretto.Config{
cache, err = ristretto.NewCache[string, any](&ristretto.Config[string, any]{
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.
@ -21,15 +21,15 @@ func Init() {
}
}
func Set(key interface{}, value interface{}, ttl time.Duration) {
func Set(key string, value interface{}, ttl time.Duration) {
cache.SetWithTTL(key, value, 0, ttl)
cache.Wait()
}
func Get(key interface{}) (value interface{}, ok bool) {
func Get(key string) (value interface{}, ok bool) {
return cache.Get(key)
}
func Del(key interface{}) {
func Del(key string) {
cache.Del(key)
}