46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package repositories
|
|
|
|
import (
|
|
"go-eve-pi/types"
|
|
|
|
logger "git.site.quack-lab.dev/dave/cylogger"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// CacheRepository handles cache-related database operations
|
|
// Implements CacheRepositoryInterface
|
|
type CacheRepository struct {
|
|
*BaseRepository
|
|
}
|
|
|
|
// NewCacheRepository creates a new cache repository
|
|
func NewCacheRepository(db *gorm.DB) *CacheRepository {
|
|
return &CacheRepository{
|
|
BaseRepository: NewBaseRepository(db),
|
|
}
|
|
}
|
|
|
|
// 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)
|
|
var entry types.CacheEntry
|
|
err := r.db.Where("url_hash = ?", urlHash).First(&entry).Error
|
|
if err != nil {
|
|
logger.Debug("No cache entry found for hash %s: %v", urlHash, err)
|
|
return nil, err
|
|
}
|
|
logger.Debug("Cache entry found for hash %s", urlHash)
|
|
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)
|
|
err := r.db.Save(entry).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
logger.Debug("Cache entry saved successfully for hash %s", entry.URLHash)
|
|
return nil
|
|
}
|