@@ -55,17 +55,46 @@ export class DataStore {
5555 */
5656 public async recreate ( ) {
5757 await localforage . dropInstance ( {
58- name : " quartz-syncer/cache/" + this . appId ,
58+ name : ` quartz-syncer/cache/${ this . vaultName } / ${ this . appId } / ${ this . version } ` ,
5959 } ) ;
6060
61+ await this . dropOutdatedCache ( ) ;
62+
6163 this . persister = localforage . createInstance ( {
62- name : " quartz-syncer/cache/" + this . appId ,
64+ name : ` quartz-syncer/cache/${ this . vaultName } / ${ this . appId } / ${ this . version } ` ,
6365 driver : [ localforage . INDEXEDDB ] ,
6466 description :
6567 "Cache metadata about files and sections in the quartz syncer index." ,
6668 } ) ;
6769 }
6870
71+ /**
72+ * Drop outdated cache instance. This is used to clear the cache when the version changes.
73+ *
74+ * returns A promise that resolves when the cache is dropped.
75+ */
76+ public async dropOutdatedCache ( ) : Promise < void > {
77+ // Get all IndexedDB instances
78+ const instances = await indexedDB . databases ( ) ;
79+
80+ // Filter instances that match the current vault and app ID
81+ const matchingInstances = instances . filter (
82+ ( instance ) =>
83+ instance . name &&
84+ instance . name . startsWith (
85+ `quartz-syncer/cache/${ this . vaultName } /${ this . appId } /` ,
86+ ) &&
87+ instance . name !==
88+ `quartz-syncer/cache/${ this . vaultName } /${ this . appId } /${ this . version } ` , // Exclude the current version
89+ ) ;
90+
91+ // Drop each matching instance
92+ for ( const instance of matchingInstances ) {
93+ // instance.name is guaranteed to be non-null due to the filter above
94+ indexedDB . deleteDatabase ( instance . name ! ) ;
95+ }
96+ }
97+
6998 /**
7099 * Check if a local file is outdated compared to the given timestamp and version.
71100 *
0 commit comments