@@ -271,6 +271,24 @@ export default class QuartzSyncer extends Plugin {
271271 this . togglePublishFlag ( ) ;
272272 } ,
273273 } ) ;
274+
275+ if ( this . settings . useCache ) {
276+ this . addCommand ( {
277+ id : "clear-cache-for-active-file" ,
278+ name : "Clear cache for active file" ,
279+ callback : async ( ) => {
280+ await this . clearCacheForActiveFile ( ) ;
281+ } ,
282+ } ) ;
283+
284+ this . addCommand ( {
285+ id : "clear-cache-for-all-files" ,
286+ name : "Clear cache for all files" ,
287+ callback : async ( ) => {
288+ await this . clearCacheForAllFiles ( ) ;
289+ } ,
290+ } ) ;
291+ }
274292 }
275293
276294 /**
@@ -294,6 +312,58 @@ export default class QuartzSyncer extends Plugin {
294312 return activeFile ;
295313 }
296314
315+ /**
316+ * Clears the cache for the currently active file.
317+ * If no file is active, it does nothing.
318+ */
319+ async clearCacheForActiveFile ( ) {
320+ const activeFile = this . getActiveFile ( this . app . workspace ) ;
321+
322+ if ( ! activeFile ) {
323+ return ;
324+ }
325+
326+ const cacheKey = `file:${ activeFile . path } ` ;
327+
328+ if ( this . settings . useCache ) {
329+ await this . datastore . persister . removeItem ( cacheKey ) ;
330+ Logger . info ( `Cache cleared for file: ${ activeFile . path } ` ) ;
331+ new Notice ( `Cache cleared for file: ${ activeFile . path } ` ) ;
332+ } else {
333+ Logger . warn ( "Cache is disabled, no action taken." ) ;
334+ new Notice ( "Cache is disabled, no action taken." ) ;
335+ }
336+ }
337+
338+ /**
339+ * Clears the cache for all files.
340+ * This method removes all cached data from the datastore.
341+ * If the cache is disabled, it does nothing.
342+ * It will show a confirmation dialog before clearing the cache.
343+ */
344+ async clearCacheForAllFiles ( ) {
345+ // Show confirmation dialog before clearing the cache
346+ const confirmation = confirm (
347+ "Are you sure you want to clear the Quartz Syncer cache for all files? This action cannot be undone." ,
348+ ) ;
349+
350+ if ( ! confirmation ) {
351+ Logger . info ( "Cache clearing cancelled by user." ) ;
352+ new Notice ( "Cache clearing cancelled." ) ;
353+
354+ return ;
355+ }
356+
357+ if ( this . settings . useCache ) {
358+ await this . datastore . recreate ( ) ;
359+ Logger . info ( "Cache cleared for all files." ) ;
360+ new Notice ( "Cache cleared for all files." ) ;
361+ } else {
362+ Logger . warn ( "Cache is disabled, no action taken." ) ;
363+ new Notice ( "Cache is disabled, no action taken." ) ;
364+ }
365+ }
366+
297367 /**
298368 * Sets the publication flag value in the frontmatter of the active file.
299369 * If no file is active, it does nothing.
0 commit comments