newRedisCache sets up a Redis-backed cache with local caching (TinyLFU). Parameters: - addresses: The Redis server addresses to connect to. Returns a RedisCache instance and an error if the connection fails.
(addresses []string, skipTLSVerify bool, poolSize int, minIdleConns int)
| 96 | // - addresses: The Redis server addresses to connect to. |
| 97 | // Returns a RedisCache instance and an error if the connection fails. |
| 98 | func newRedisCache(addresses []string, skipTLSVerify bool, poolSize int, minIdleConns int) (*RedisCache, error) { |
| 99 | // Initialize the Redis client using the provided addresses |
| 100 | client, err := redis_db.NewRedisClient(addresses, skipTLSVerify, &redis_db.PoolConfig{ |
| 101 | PoolSize: poolSize, |
| 102 | MinIdleConns: minIdleConns, |
| 103 | }) |
| 104 | if err != nil { |
| 105 | return nil, err |
| 106 | } |
| 107 | |
| 108 | // Create a cache instance with Redis and local cache support |
| 109 | c := cache.New(&cache.Options{ |
| 110 | Redis: client.Client(), |
| 111 | LocalCache: cache.NewTinyLFU(cacheSize, 1*time.Minute), // Local cache uses TinyLFU eviction policy |
| 112 | }) |
| 113 | |
| 114 | return &RedisCache{cache: c}, nil |
| 115 | } |
| 116 | |
| 117 | // Set adds a new entry to the cache with a specified key and TTL. |
| 118 | // Parameters: |