Skip to content

Commit

Permalink
Remove from cache when done downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
mohnjiles committed Aug 1, 2023
1 parent b10a1ae commit 5a771df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,15 @@ private void UpdateModelCards(IEnumerable<CivitModel>? models, CivitMetadata? me
var updateCards = models
.Select(model =>
{
if (cache.Get(model.Id) != null)
var cachedViewModel = cache.Get(model.Id);
if (cachedViewModel != null)
{
return cache.Get(model.Id);
if (!cachedViewModel.IsImporting)
{
cache.Remove(model.Id);
}
return cachedViewModel;
}
var newCard = new CheckpointBrowserCardViewModel(model,
Expand Down
9 changes: 9 additions & 0 deletions StabilityMatrix.Core/Helper/Cache/LRUCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ public void Add(TK key, TV val)
cacheMap[key] = node;
}

[MethodImpl(MethodImplOptions.Synchronized)]
public void Remove(TK key)
{
if (!cacheMap.TryGetValue(key, out var node)) return;

lruList.Remove(node);
cacheMap.Remove(key);
}

private void RemoveFirst()
{
// Remove from LRUPriority
Expand Down

0 comments on commit 5a771df

Please sign in to comment.