Deretardify the caching

This commit is contained in:
2025-10-11 10:33:03 +02:00
parent 6c1e9310c5
commit 22b218c7d3
6 changed files with 401 additions and 476 deletions

View File

@@ -1,6 +1,7 @@
package repositories
import (
"fmt"
"go-eve-pi/types"
logger "git.site.quack-lab.dev/dave/cylogger"
@@ -21,25 +22,27 @@ func NewCacheRepository(db *gorm.DB) *CacheRepository {
}
// GetCacheEntry retrieves a cache entry by URL hash
func (r *CacheRepository) GetCacheEntry(urlHash string) (*types.CacheEntry, error) {
logger.Debug("Fetching cache entry for hash: %s", urlHash)
func (r *CacheRepository) GetCacheEntry(hash string) (*types.CacheEntry, error) {
funclog := logger.Default.WithPrefix("CacheRepository.GetCacheEntry").WithPrefix(fmt.Sprintf("hash=%s", hash))
funclog.Info("Starting")
var entry types.CacheEntry
err := r.db.Where("url_hash = ?", urlHash).First(&entry).Error
err := r.db.Where("hash = ?", hash).First(&entry).Error
if err != nil {
logger.Debug("No cache entry found for hash %s: %v", urlHash, err)
funclog.Debug("No cache entry found: %v", err)
return nil, err
}
logger.Debug("Cache entry found for hash %s", urlHash)
funclog.Debug("Cache entry found")
return &entry, nil
}
// SaveCacheEntry saves a cache entry to the database
func (r *CacheRepository) SaveCacheEntry(entry *types.CacheEntry) error {
logger.Debug("Saving cache entry for hash: %s", entry.URLHash)
funclog := logger.Default.WithPrefix("CacheRepository.SaveCacheEntry").WithPrefix(fmt.Sprintf("hash=%s", entry.Hash))
funclog.Info("Starting")
err := r.db.Save(entry).Error
if err != nil {
return err
}
logger.Debug("Cache entry saved successfully for hash %s", entry.URLHash)
funclog.Debug("Cache entry saved successfully")
return nil
}