This commit is contained in:
@@ -73,7 +73,7 @@ type (
|
||||
AllHist(gameID GameIdentifier) ([]string, error)
|
||||
|
||||
WriteBlob(ID Identifier) (io.Writer, error)
|
||||
WriteMetadata(gameID GameIdentifier, m Metadata) error
|
||||
WriteMetadata(gameID GameIdentifier, m Metadata) error
|
||||
|
||||
Metadata(gameID GameIdentifier) (Metadata, error)
|
||||
LastScan(gameID GameIdentifier) (time.Time, error)
|
||||
@@ -401,6 +401,7 @@ func (r *EagerRepository) Preload() error {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
slog.Info("loading data from datastore to memory...")
|
||||
games, err := r.Repository.All()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load all data: %w", err)
|
||||
@@ -443,6 +444,21 @@ func (r *EagerRepository) Preload() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *EagerRepository) ClearCache() {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
slog.Info("clearing cache...")
|
||||
for k := range r.data {
|
||||
delete(r.data, k)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *EagerRepository) Reload() error {
|
||||
r.ClearCache()
|
||||
return r.Preload()
|
||||
}
|
||||
|
||||
func (r *EagerRepository) All() ([]string, error) {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user