aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.dev>2025-02-03 22:35:55 +0200
committerBozhidar Batsov <bozhidar@batsov.dev>2025-02-03 22:35:55 +0200
commita4a6cacd908bc614d60c6233a7f224baebfe1178 (patch)
treec6fe53dbcfbaeab250691d4aef471ed7fbcedf49
parent0efac68c82d8ebdb3fd83ea5e530c4b816c87f8f (diff)
Make the cache transient by default
-rw-r--r--CHANGELOG.md2
-rw-r--r--doc/modules/ROOT/pages/configuration.adoc11
-rw-r--r--projectile.el20
-rw-r--r--test/projectile-test.el6
4 files changed, 30 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 06c0645..118327c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -48,6 +48,8 @@
* `c t` -> `projectile-test-project`
* `c r` -> `projectile-run-project`
* The old keybindings will be removed in a future version of Projectile.
+* Make the cache transient by default. (meaning it lives only in memory and is not persisted to a file)
+ * To enable persistent caching you need to set `projectile-enable-caching` to `'persistent`.
## 2.8.0 (2023-10-13)
diff --git a/doc/modules/ROOT/pages/configuration.adoc b/doc/modules/ROOT/pages/configuration.adoc
index 59ee907..135d771 100644
--- a/doc/modules/ROOT/pages/configuration.adoc
+++ b/doc/modules/ROOT/pages/configuration.adoc
@@ -149,7 +149,16 @@ Pressing kbd:[s-p z] will add the currently visited file to the
cache for current project. Generally files created outside Emacs will
be added to the cache automatically the first time you open them.
-The project cache is persistent and will be preserved during Emacs restarts.
+Normally the cache lasts for the duration of your Emacs session.
+If you want to cache to persist between Emacs sessions you
+should set this option to `'persistent`.
+
+[source,elisp]
+----
+(setq projectile-enable-caching 'persistent)
+----
+
+Now the project cache is persistent and will be preserved during Emacs restarts.
Each project gets its own cache file, that will be placed in the root folder of the
project. The name of the cache file is `.projectile-cache.eld` by default, but you can tweak it
if you want to:
diff --git a/projectile.el b/projectile.el
index 1f8f6c2..0f318c7 100644
--- a/projectile.el
+++ b/projectile.el
@@ -137,10 +137,17 @@ default on all operating systems, except Windows."
(defcustom projectile-enable-caching (eq projectile-indexing-method 'native)
"When t enables project files caching.
+Normally the cache lasts for the duration of your Emacs session.
+If you want to cache to persist between Emacs sessions you
+should set this option to `'persistent'.
+
Project caching is automatically enabled by default if you're
using the native indexing method."
:group 'projectile
- :type 'boolean)
+ :type '(radio
+ (const :tag "Disabled" nil)
+ (const :tag "Transient" t)
+ (const :tag "Persistent" persistent)))
(defcustom projectile-kill-buffers-filter 'kill-all
"Determine which buffers are killed by `projectile-kill-buffers'.
@@ -1110,9 +1117,9 @@ to invalidate."
(defun projectile-cache-project (project files)
"Cache PROJECTs FILES.
The cache is created both in memory and on the hard drive."
- (when projectile-enable-caching
- (puthash project files projectile-projects-cache)
- (puthash project (projectile-time-seconds) projectile-projects-cache-time)
+ (puthash project files projectile-projects-cache)
+ (puthash project (projectile-time-seconds) projectile-projects-cache-time)
+ (when (eq projectile-enable-caching 'persistent)
(projectile-serialize files (projectile-project-cache-file project))))
(defun projectile-load-project-cache (project-root)
@@ -2168,7 +2175,10 @@ project-root for every file."
;; Use the cache, if requested and available.
(when projectile-enable-caching
(setq files (or (gethash project-root projectile-projects-cache)
- (projectile-load-project-cache project-root))))
+ ;; load the cache from disk only if persistent cache is
+ ;; enabled
+ (and (eq projectile-enable-caching 'persistent)
+ (projectile-load-project-cache project-root)))))
;; Calculate the list of files.
(when (null files)
diff --git a/test/projectile-test.el b/test/projectile-test.el
index 8c62a63..9df08aa 100644
--- a/test/projectile-test.el
+++ b/test/projectile-test.el
@@ -81,7 +81,7 @@ You'd normally combine this with `projectile-test-with-sandbox'."
`(let ((projectile-indexing-method 'native)
(projectile-projects-cache (make-hash-table :test 'equal))
(projectile-projects-cache-time (make-hash-table :test 'equal))
- (projectile-enable-caching t))
+ (projectile-enable-caching 'persistent))
,@(mapcar (lambda (file)
(let* ((path (concat "project/" file))
(dir (file-name-directory path)))
@@ -853,7 +853,7 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'.
(cd "project")
(let ((projectile-projects-cache (make-hash-table :test #'equal))
(projectile-projects-cache-time (make-hash-table :test #'equal))
- (projectile-enable-caching t))
+ (projectile-enable-caching 'persistent))
(puthash (projectile-project-root)
'("file1.el")
projectile-projects-cache)
@@ -881,7 +881,7 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'.
(cd "project")
(let ((projectile-projects-cache (make-hash-table :test #'equal))
(projectile-projects-cache-time (make-hash-table :test #'equal))
- (projectile-enable-caching t)
+ (projectile-enable-caching 'persistent)
(projectile-files-cache-expire 10))
;; Create a stale cache with only one file in it.
(puthash (projectile-project-root)