Skip to content

Commit 1cc1865

Browse files
committed
docs(router): update jwt cache eviction documentation to reflect random eviction
Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
1 parent 7515a04 commit 1cc1865

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

pkg/router/jwt.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const keyCacheMaxSize = 1000
111111

112112
// GenerateTokenWithKey generates a JWT token signed with a specific PEM-encoded
113113
// private key. The parsed key is cached to avoid repeated RSA parsing overhead.
114-
// Eviction is FIFO-based: the oldest entry is removed when the cache is full,
114+
// Eviction is random-based: a random entry is removed when the cache is full,
115115
// avoiding the thundering-herd problem of wiping the entire cache at once.
116116
func (jm *JWTManager) GenerateTokenWithKey(claims map[string]interface{}, privateKeyPEM string) (string, error) {
117117
jm.cacheMu.RLock()
@@ -126,10 +126,10 @@ func (jm *JWTManager) GenerateTokenWithKey(claims map[string]interface{}, privat
126126
privKey = parsedKey
127127

128128
jm.cacheMu.Lock()
129-
// Evict the single oldest entry when at capacity instead of clearing all.
129+
// Evict a single random entry when at capacity instead of clearing all.
130130
if len(jm.keyCache) >= keyCacheMaxSize {
131-
for oldest := range jm.keyCache {
132-
delete(jm.keyCache, oldest)
131+
for k := range jm.keyCache {
132+
delete(jm.keyCache, k)
133133
break
134134
}
135135
}

0 commit comments

Comments
 (0)