Skip to content

Commit

Permalink
Invalidate cache based on db mtime
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-shariff committed Nov 30, 2024
1 parent 2c803f6 commit 661e388
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions org-roam-ql.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
(defvar org-roam-ql--sort-functions (make-hash-table :test 'equal) "Holds the function to sort nodes.")
(defvar org-roam-ql--saved-queries (make-hash-table :test 'equal) "Holds the saved queries.")
(defvar org-roam-ql--cache (make-hash-table))
(defvar org-roam-ql--db-mtime nil)
(defvar org-roam-ql--search-query-history '() "History of queries with `org-roam-ql-search'.")
(defvar-local org-roam-ql-buffer-title nil "The current title of the buffer.")
(defvar-local org-roam-ql-buffer-query nil "The current query of the buffer.")
Expand Down Expand Up @@ -166,6 +167,13 @@ See `org-roam-ql-nodes' for information on SOURCE-OR-QUERY.
Not caching or invalidating in the top level function as the
database/buffers can change. Currently this is only used by the
internal functions"
(let ((db-mtime (time-convert
(file-attribute-modification-time
(file-attributes (file-truename org-roam-db-location)))
'integer)))
(unless (equal db-mtime org-roam-ql--db-mtime)
(org-roam-ql-clear-cache)
(setq org-roam-ql--db-mtime db-mtime)))
(let ((cached-value (gethash source-or-query org-roam-ql--cache)))
(if cached-value
cached-value
Expand Down

0 comments on commit 661e388

Please sign in to comment.