Hallucinate a whole lot of shit...
Too much shit...
This commit is contained in:
44
repositories/cache.go
Normal file
44
repositories/cache.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"go-eve-pi/types"
|
||||
|
||||
logger "git.site.quack-lab.dev/dave/cylogger"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CacheRepository handles cache-related database operations
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user