@@ -15,98 +15,6 @@ internal class PersistentSQLiteCacheAdapter : IFileListCache, IDisposable
15
15
private SqliteConnection connection ;
16
16
private bool disposedValue ;
17
17
18
- public async Task SaveFileListToCache ( string path , CacheEntry cacheEntry )
19
- {
20
- if ( ! await InitializeIfNeeded ( ) )
21
- {
22
- return ;
23
- }
24
- const int maxCachedEntries = 128 ;
25
- try
26
- {
27
- if ( cacheEntry == null )
28
- {
29
- using var deleteCommand = new SqliteCommand ( "DELETE FROM FileListCache WHERE Id = @Id" , connection ) ;
30
- deleteCommand . Parameters . Add ( "@Id" , SqliteType . Text ) . Value = path ;
31
- await deleteCommand . ExecuteNonQueryAsync ( ) ;
32
- return ;
33
- }
34
-
35
- if ( cacheEntry . FileList . Count > maxCachedEntries )
36
- {
37
- cacheEntry . FileList = cacheEntry . FileList . Take ( maxCachedEntries ) . ToList ( ) ;
38
- }
39
-
40
- using var cmd = new SqliteCommand ( "SELECT Id FROM FileListCache WHERE Id = @Id" , connection ) ;
41
- cmd . Parameters . Add ( "@Id" , SqliteType . Text ) . Value = path ;
42
- using var reader = await cmd . ExecuteReaderAsync ( ) ;
43
- if ( reader . HasRows )
44
- {
45
- // need to update entry
46
- using var updateCommand = new SqliteCommand ( "UPDATE FileListCache SET Timestamp = @Timestamp, Entry = @Entry WHERE Id = @Id" , connection ) ;
47
- updateCommand . Parameters . Add ( "@Id" , SqliteType . Text ) . Value = path ;
48
- updateCommand . Parameters . Add ( "@Timestamp" , SqliteType . Integer ) . Value = GetTimestamp ( DateTime . UtcNow ) ;
49
- var settings = new JsonSerializerSettings
50
- {
51
- TypeNameHandling = TypeNameHandling . Auto
52
- } ;
53
- updateCommand . Parameters . Add ( "@Entry" , SqliteType . Text ) . Value = JsonConvert . SerializeObject ( cacheEntry , settings ) ;
54
- await updateCommand . ExecuteNonQueryAsync ( ) ;
55
- }
56
- else
57
- {
58
- // need to insert entry
59
- using var insertCommand = new SqliteCommand ( "INSERT INTO FileListCache (Id, Timestamp, Entry) VALUES (@Id, @Timestamp, @Entry)" , connection ) ;
60
- insertCommand . Parameters . Add ( "@Id" , SqliteType . Text ) . Value = path ;
61
- insertCommand . Parameters . Add ( "@Timestamp" , SqliteType . Integer ) . Value = GetTimestamp ( DateTime . UtcNow ) ;
62
- var settings = new JsonSerializerSettings
63
- {
64
- TypeNameHandling = TypeNameHandling . Auto
65
- } ;
66
- insertCommand . Parameters . Add ( "@Entry" , SqliteType . Text ) . Value = JsonConvert . SerializeObject ( cacheEntry , settings ) ;
67
- await insertCommand . ExecuteNonQueryAsync ( ) ;
68
- }
69
- }
70
- catch ( Exception ex )
71
- {
72
- NLog . LogManager . GetCurrentClassLogger ( ) . Warn ( ex , ex . Message ) ;
73
- }
74
- }
75
-
76
- public async Task < CacheEntry > ReadFileListFromCache ( string path , CancellationToken cancellationToken )
77
- {
78
- if ( ! await InitializeIfNeeded ( ) )
79
- {
80
- return null ;
81
- }
82
- try
83
- {
84
- using var cmd = new SqliteCommand ( "SELECT Timestamp, Entry FROM FileListCache WHERE Id = @Id" , connection ) ;
85
- cmd . Parameters . Add ( "@Id" , SqliteType . Text ) . Value = path ;
86
-
87
- using var reader = await cmd . ExecuteReaderAsync ( cancellationToken ) ;
88
- if ( ! await reader . ReadAsync ( ) )
89
- {
90
- return null ;
91
- }
92
- var timestamp = reader . GetInt64 ( 0 ) ;
93
- var entryAsJson = reader . GetString ( 1 ) ;
94
- var settings = new JsonSerializerSettings
95
- {
96
- TypeNameHandling = TypeNameHandling . Auto
97
- } ;
98
- var entry = JsonConvert . DeserializeObject < CacheEntry > ( entryAsJson , settings ) ;
99
- entry . CurrentFolder . ItemPropertiesInitialized = false ;
100
- entry . FileList . ForEach ( ( item ) => item . ItemPropertiesInitialized = false ) ;
101
- return entry ;
102
- }
103
- catch ( Exception ex )
104
- {
105
- NLog . LogManager . GetCurrentClassLogger ( ) . Warn ( ex , ex . Message ) ;
106
- return null ;
107
- }
108
- }
109
-
110
18
public async Task SaveFileDisplayNameToCache ( string path , string displayName )
111
19
{
112
20
if ( ! await InitializeIfNeeded ( ) )
@@ -174,11 +82,6 @@ public async Task<string> ReadFileDisplayNameFromCache(string path, Cancellation
174
82
}
175
83
}
176
84
177
- private long GetTimestamp ( DateTime dateTime )
178
- {
179
- return new DateTimeOffset ( dateTime ) . ToUnixTimeSeconds ( ) ;
180
- }
181
-
182
85
public void Dispose ( )
183
86
{
184
87
if ( ! disposedValue )
@@ -190,23 +93,6 @@ public void Dispose()
190
93
191
94
private void RunCleanupRoutine ( )
192
95
{
193
- Task . Run ( async ( ) =>
194
- {
195
- try
196
- {
197
- // remove entries that are 1 month old (timestamp is updated every time the cache is set)
198
- var limitTimestamp = GetTimestamp ( DateTime . Now . AddMonths ( - 1 ) ) ;
199
- using var cmd = new SqliteCommand ( "DELETE FROM FileListCache WHERE Timestamp < @Timestamp" , connection ) ;
200
- cmd . Parameters . Add ( "@Timestamp" , SqliteType . Integer ) . Value = limitTimestamp ;
201
-
202
- var count = await cmd . ExecuteNonQueryAsync ( ) . ConfigureAwait ( false ) ;
203
- Debug . WriteLine ( $ "Removed { count } old entries from cache database") ;
204
- }
205
- catch ( Exception ex )
206
- {
207
- NLog . LogManager . GetCurrentClassLogger ( ) . Warn ( ex , ex . Message ) ;
208
- }
209
- } ) ;
210
96
}
211
97
212
98
private async Task < bool > InitializeIfNeeded ( )
@@ -227,15 +113,6 @@ private async Task<bool> InitializeIfNeeded()
227
113
connection . Open ( ) ;
228
114
229
115
// create db schema
230
- var createFileListCacheTable = @"CREATE TABLE IF NOT EXISTS ""FileListCache"" (
231
- ""Id"" VARCHAR(5000) NOT NULL,
232
- ""Timestamp"" INTEGER NOT NULL,
233
- ""Entry"" TEXT NOT NULL,
234
- PRIMARY KEY(""Id"")
235
- )" ;
236
- using var cmdFileListCacheTable = new SqliteCommand ( createFileListCacheTable , connection ) ;
237
- cmdFileListCacheTable . ExecuteNonQuery ( ) ;
238
-
239
116
var createFileDisplayNameCacheTable = @"CREATE TABLE IF NOT EXISTS ""FileDisplayNameCache"" (
240
117
""Id"" VARCHAR(5000) NOT NULL,
241
118
""DisplayName"" TEXT NOT NULL,
0 commit comments