Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
8d30594e
Unverified
Commit
8d30594e
authored
Feb 23, 2024
by
felipe
Committed by
GitHub
Feb 23, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(proxyd): change default cache ttl to 2 hours and make it configurable (#9645)
parent
a58ea471
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
7 deletions
+12
-7
cache.go
proxyd/cache.go
+4
-5
config.go
proxyd/config.go
+2
-1
proxyd.go
proxyd/proxyd.go
+5
-1
server.go
proxyd/server.go
+1
-0
No files found.
proxyd/cache.go
View file @
8d30594e
...
@@ -21,8 +21,6 @@ type Cache interface {
...
@@ -21,8 +21,6 @@ type Cache interface {
const
(
const
(
// assuming an average RPCRes size of 3 KB
// assuming an average RPCRes size of 3 KB
memoryCacheLimit
=
4096
memoryCacheLimit
=
4096
// Set a large ttl to avoid expirations. However, a ttl must be set for volatile-lru to take effect.
redisTTL
=
30
*
7
*
24
*
time
.
Hour
)
)
type
cache
struct
{
type
cache
struct
{
...
@@ -49,10 +47,11 @@ func (c *cache) Put(ctx context.Context, key string, value string) error {
...
@@ -49,10 +47,11 @@ func (c *cache) Put(ctx context.Context, key string, value string) error {
type
redisCache
struct
{
type
redisCache
struct
{
rdb
*
redis
.
Client
rdb
*
redis
.
Client
prefix
string
prefix
string
ttl
time
.
Duration
}
}
func
newRedisCache
(
rdb
*
redis
.
Client
,
prefix
string
)
*
redisCache
{
func
newRedisCache
(
rdb
*
redis
.
Client
,
prefix
string
,
ttl
time
.
Duration
)
*
redisCache
{
return
&
redisCache
{
rdb
,
prefix
}
return
&
redisCache
{
rdb
,
prefix
,
ttl
}
}
}
func
(
c
*
redisCache
)
namespaced
(
key
string
)
string
{
func
(
c
*
redisCache
)
namespaced
(
key
string
)
string
{
...
@@ -78,7 +77,7 @@ func (c *redisCache) Get(ctx context.Context, key string) (string, error) {
...
@@ -78,7 +77,7 @@ func (c *redisCache) Get(ctx context.Context, key string) (string, error) {
func
(
c
*
redisCache
)
Put
(
ctx
context
.
Context
,
key
string
,
value
string
)
error
{
func
(
c
*
redisCache
)
Put
(
ctx
context
.
Context
,
key
string
,
value
string
)
error
{
start
:=
time
.
Now
()
start
:=
time
.
Now
()
err
:=
c
.
rdb
.
SetEx
(
ctx
,
c
.
namespaced
(
key
),
value
,
redisTTL
)
.
Err
()
err
:=
c
.
rdb
.
SetEx
(
ctx
,
c
.
namespaced
(
key
),
value
,
c
.
ttl
)
.
Err
()
redisCacheDurationSumm
.
WithLabelValues
(
"SETEX"
)
.
Observe
(
float64
(
time
.
Since
(
start
)
.
Milliseconds
()))
redisCacheDurationSumm
.
WithLabelValues
(
"SETEX"
)
.
Observe
(
float64
(
time
.
Since
(
start
)
.
Milliseconds
()))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
proxyd/config.go
View file @
8d30594e
...
@@ -29,7 +29,8 @@ type ServerConfig struct {
...
@@ -29,7 +29,8 @@ type ServerConfig struct {
}
}
type
CacheConfig
struct
{
type
CacheConfig
struct
{
Enabled
bool
`toml:"enabled"`
Enabled
bool
`toml:"enabled"`
TTL
TOMLDuration
`toml:"ttl"`
}
}
type
RedisConfig
struct
{
type
RedisConfig
struct
{
...
...
proxyd/proxyd.go
View file @
8d30594e
...
@@ -235,7 +235,11 @@ func Start(config *Config) (*Server, func(), error) {
...
@@ -235,7 +235,11 @@ func Start(config *Config) (*Server, func(), error) {
log
.
Warn
(
"redis is not configured, using in-memory cache"
)
log
.
Warn
(
"redis is not configured, using in-memory cache"
)
cache
=
newMemoryCache
()
cache
=
newMemoryCache
()
}
else
{
}
else
{
cache
=
newRedisCache
(
redisClient
,
config
.
Redis
.
Namespace
)
ttl
:=
defaultCacheTtl
if
config
.
Cache
.
TTL
!=
0
{
ttl
=
time
.
Duration
(
config
.
Cache
.
TTL
)
}
cache
=
newRedisCache
(
redisClient
,
config
.
Redis
.
Namespace
,
ttl
)
}
}
rpcCache
=
newRPCCache
(
newCacheWithCompression
(
cache
))
rpcCache
=
newRPCCache
(
newCacheWithCompression
(
cache
))
}
}
...
...
proxyd/server.go
View file @
8d30594e
...
@@ -42,6 +42,7 @@ const (
...
@@ -42,6 +42,7 @@ const (
defaultWSHandshakeTimeout
=
10
*
time
.
Second
defaultWSHandshakeTimeout
=
10
*
time
.
Second
defaultWSReadTimeout
=
2
*
time
.
Minute
defaultWSReadTimeout
=
2
*
time
.
Minute
defaultWSWriteTimeout
=
10
*
time
.
Second
defaultWSWriteTimeout
=
10
*
time
.
Second
defaultCacheTtl
=
1
*
time
.
Hour
maxRequestBodyLogLen
=
2000
maxRequestBodyLogLen
=
2000
defaultMaxUpstreamBatchSize
=
10
defaultMaxUpstreamBatchSize
=
10
defaultRateLimitHeader
=
"X-Forwarded-For"
defaultRateLimitHeader
=
"X-Forwarded-For"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment