File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
116116func (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 }
You can’t perform that action at this time.
0 commit comments