Skip to content

Commit

Permalink
Remove SQLite cache
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 committed Sep 4, 2021
1 parent 1384af8 commit ea39852
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 149 deletions.
1 change: 0 additions & 1 deletion Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@
<Compile Include="Helpers\Extension.cs" />
<Compile Include="Helpers\FileListCache\FileListCacheController.cs" />
<Compile Include="Helpers\FileListCache\IFileListCache.cs" />
<Compile Include="Helpers\FileListCache\PersistentSQLiteCacheAdapter.cs" />
<Compile Include="Helpers\ExtensionManager.cs" />
<Compile Include="Helpers\IntervalSampler.cs" />
<Compile Include="Helpers\QuickLookHelpers.cs" />
Expand Down
30 changes: 10 additions & 20 deletions Files/Helpers/FileListCache/FileListCacheController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Files.Common;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -14,40 +13,31 @@ public static FileListCacheController GetInstance()
return instance ??= new FileListCacheController();
}

private readonly IFileListCache persistentAdapter;

private FileListCacheController()
{
persistentAdapter = new PersistentSQLiteCacheAdapter();
}

private readonly Dictionary<string, object> fileNamesCache = new Dictionary<string, object>();
private readonly ConcurrentDictionary<string, string> fileNamesCache = new ConcurrentDictionary<string, string>();

public async Task<string> ReadFileDisplayNameFromCache(string path, CancellationToken cancellationToken)
public Task<string> ReadFileDisplayNameFromCache(string path, CancellationToken cancellationToken)
{
var displayName = fileNamesCache.Get(path, (string)null);
if (displayName == null)
if (fileNamesCache.TryGetValue(path, out var displayName))
{
displayName = await persistentAdapter.ReadFileDisplayNameFromCache(path, cancellationToken);
if (displayName != null)
{
fileNamesCache[path] = displayName;
}
return Task.FromResult(displayName);
}
return displayName;

return Task.FromResult<string>(null);
}

public Task SaveFileDisplayNameToCache(string path, string displayName)
{
if (displayName == null)
{
fileNamesCache.Remove(path);
return persistentAdapter.SaveFileDisplayNameToCache(path, displayName);
fileNamesCache.TryRemove(path, out _);
}
fileNamesCache[path] = displayName;

// save entry to persistent cache in background
return persistentAdapter.SaveFileDisplayNameToCache(path, displayName);
fileNamesCache[path] = displayName;
return Task.CompletedTask;
}
}
}
128 changes: 0 additions & 128 deletions Files/Helpers/FileListCache/PersistentSQLiteCacheAdapter.cs

This file was deleted.

0 comments on commit ea39852

Please sign in to comment.