Deretardify the caching
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user