Refactor caching logic and enhance hash generation in steamcache
- Replaced SHA1 hash calculations with SHA256 for improved security and consistency in cache key generation. - Introduced a new TestURLHashing function to validate the new cache key generation logic. - Removed outdated hash calculation tests and streamlined the caching process to focus on URL-based hashing. - Implemented lightweight validation methods in ServeHTTP to enhance performance and reliability of cached responses. - Added batched time updates in VFS implementations for better performance during access time tracking.
This commit is contained in:
33
vfs/vfs.go
33
vfs/vfs.go
@@ -69,6 +69,39 @@ func (fi *FileInfo) UpdateAccess() {
|
||||
fi.AccessCount++
|
||||
}
|
||||
|
||||
// BatchedTimeUpdate provides a way to batch time updates for better performance
|
||||
type BatchedTimeUpdate struct {
|
||||
currentTime time.Time
|
||||
lastUpdate time.Time
|
||||
updateInterval time.Duration
|
||||
}
|
||||
|
||||
// NewBatchedTimeUpdate creates a new batched time updater
|
||||
func NewBatchedTimeUpdate(interval time.Duration) *BatchedTimeUpdate {
|
||||
now := time.Now()
|
||||
return &BatchedTimeUpdate{
|
||||
currentTime: now,
|
||||
lastUpdate: now,
|
||||
updateInterval: interval,
|
||||
}
|
||||
}
|
||||
|
||||
// GetTime returns the current cached time, updating it if necessary
|
||||
func (btu *BatchedTimeUpdate) GetTime() time.Time {
|
||||
now := time.Now()
|
||||
if now.Sub(btu.lastUpdate) >= btu.updateInterval {
|
||||
btu.currentTime = now
|
||||
btu.lastUpdate = now
|
||||
}
|
||||
return btu.currentTime
|
||||
}
|
||||
|
||||
// UpdateAccessBatched updates the access time using batched time updates
|
||||
func (fi *FileInfo) UpdateAccessBatched(btu *BatchedTimeUpdate) {
|
||||
fi.ATime = btu.GetTime()
|
||||
fi.AccessCount++
|
||||
}
|
||||
|
||||
// GetTimeDecayedScore calculates a score based on access time and frequency
|
||||
// More recent and frequent accesses get higher scores
|
||||
func (fi *FileInfo) GetTimeDecayedScore() float64 {
|
||||
|
||||
Reference in New Issue
Block a user