mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-12 04:04:26 +00:00
Improve expiration logic.
This commit is contained in:
@@ -40,7 +40,7 @@ type Cache struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DefaultMaxSize is the default maximum number of items in the cache.
|
// DefaultMaxSize is the default maximum number of items in the cache.
|
||||||
const DefaultMaxSize = 1000
|
const DefaultMaxSize = 500
|
||||||
|
|
||||||
// NewCache creates a new empty cache instance that is ready for use.
|
// NewCache creates a new empty cache instance that is ready for use.
|
||||||
func NewCache() *Cache {
|
func NewCache() *Cache {
|
||||||
@@ -128,8 +128,8 @@ func (c *Cache) Cleanup() {
|
|||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
for key, item := range c.items {
|
for key, item := range c.items {
|
||||||
// Only remove items that are already expired
|
// Remove items that are expired or within 10% of expiration
|
||||||
if now.After(item.ExpiresAt) {
|
if now.After(item.ExpiresAt) || now.Add(time.Duration(float64(item.ExpiresAt.Sub(now))*0.1)).After(item.ExpiresAt) {
|
||||||
c.removeItem(key)
|
c.removeItem(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,15 @@ func (c *MetadataCache) GetMetadata(providerURL string, httpClient *http.Client,
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.metadata = metadata
|
c.metadata = metadata
|
||||||
|
// Calculate expiration time based on usage patterns
|
||||||
|
usageCount := 0 // This should be replaced with actual usage tracking logic
|
||||||
|
if usageCount < 10 {
|
||||||
|
c.expiresAt = time.Now().Add(30 * time.Minute)
|
||||||
|
} else if usageCount < 50 {
|
||||||
c.expiresAt = time.Now().Add(1 * time.Hour)
|
c.expiresAt = time.Now().Add(1 * time.Hour)
|
||||||
|
} else {
|
||||||
|
c.expiresAt = time.Now().Add(2 * time.Hour)
|
||||||
|
}
|
||||||
|
|
||||||
return metadata, nil
|
return metadata, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user