Skip to content

Commit a4a6cac

Browse files
committed
Make the cache transient by default
1 parent 0efac68 commit a4a6cac

4 files changed

Lines changed: 30 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
* `c t` -> `projectile-test-project`
4949
* `c r` -> `projectile-run-project`
5050
* The old keybindings will be removed in a future version of Projectile.
51+
* Make the cache transient by default. (meaning it lives only in memory and is not persisted to a file)
52+
* To enable persistent caching you need to set `projectile-enable-caching` to `'persistent`.
5153

5254
## 2.8.0 (2023-10-13)
5355

doc/modules/ROOT/pages/configuration.adoc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,16 @@ Pressing kbd:[s-p z] will add the currently visited file to the
149149
cache for current project. Generally files created outside Emacs will
150150
be added to the cache automatically the first time you open them.
151151

152-
The project cache is persistent and will be preserved during Emacs restarts.
152+
Normally the cache lasts for the duration of your Emacs session.
153+
If you want to cache to persist between Emacs sessions you
154+
should set this option to `'persistent`.
155+
156+
[source,elisp]
157+
----
158+
(setq projectile-enable-caching 'persistent)
159+
----
160+
161+
Now the project cache is persistent and will be preserved during Emacs restarts.
153162
Each project gets its own cache file, that will be placed in the root folder of the
154163
project. The name of the cache file is `.projectile-cache.eld` by default, but you can tweak it
155164
if you want to:

projectile.el

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,17 @@ default on all operating systems, except Windows."
137137
(defcustom projectile-enable-caching (eq projectile-indexing-method 'native)
138138
"When t enables project files caching.
139139
140+
Normally the cache lasts for the duration of your Emacs session.
141+
If you want to cache to persist between Emacs sessions you
142+
should set this option to `'persistent'.
143+
140144
Project caching is automatically enabled by default if you're
141145
using the native indexing method."
142146
:group 'projectile
143-
:type 'boolean)
147+
:type '(radio
148+
(const :tag "Disabled" nil)
149+
(const :tag "Transient" t)
150+
(const :tag "Persistent" persistent)))
144151

145152
(defcustom projectile-kill-buffers-filter 'kill-all
146153
"Determine which buffers are killed by `projectile-kill-buffers'.
@@ -1110,9 +1117,9 @@ to invalidate."
11101117
(defun projectile-cache-project (project files)
11111118
"Cache PROJECTs FILES.
11121119
The cache is created both in memory and on the hard drive."
1113-
(when projectile-enable-caching
1114-
(puthash project files projectile-projects-cache)
1115-
(puthash project (projectile-time-seconds) projectile-projects-cache-time)
1120+
(puthash project files projectile-projects-cache)
1121+
(puthash project (projectile-time-seconds) projectile-projects-cache-time)
1122+
(when (eq projectile-enable-caching 'persistent)
11161123
(projectile-serialize files (projectile-project-cache-file project))))
11171124

11181125
(defun projectile-load-project-cache (project-root)
@@ -2168,7 +2175,10 @@ project-root for every file."
21682175
;; Use the cache, if requested and available.
21692176
(when projectile-enable-caching
21702177
(setq files (or (gethash project-root projectile-projects-cache)
2171-
(projectile-load-project-cache project-root))))
2178+
;; load the cache from disk only if persistent cache is
2179+
;; enabled
2180+
(and (eq projectile-enable-caching 'persistent)
2181+
(projectile-load-project-cache project-root)))))
21722182

21732183
;; Calculate the list of files.
21742184
(when (null files)

test/projectile-test.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ You'd normally combine this with `projectile-test-with-sandbox'."
8181
`(let ((projectile-indexing-method 'native)
8282
(projectile-projects-cache (make-hash-table :test 'equal))
8383
(projectile-projects-cache-time (make-hash-table :test 'equal))
84-
(projectile-enable-caching t))
84+
(projectile-enable-caching 'persistent))
8585
,@(mapcar (lambda (file)
8686
(let* ((path (concat "project/" file))
8787
(dir (file-name-directory path)))
@@ -853,7 +853,7 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'.
853853
(cd "project")
854854
(let ((projectile-projects-cache (make-hash-table :test #'equal))
855855
(projectile-projects-cache-time (make-hash-table :test #'equal))
856-
(projectile-enable-caching t))
856+
(projectile-enable-caching 'persistent))
857857
(puthash (projectile-project-root)
858858
'("file1.el")
859859
projectile-projects-cache)
@@ -881,7 +881,7 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'.
881881
(cd "project")
882882
(let ((projectile-projects-cache (make-hash-table :test #'equal))
883883
(projectile-projects-cache-time (make-hash-table :test #'equal))
884-
(projectile-enable-caching t)
884+
(projectile-enable-caching 'persistent)
885885
(projectile-files-cache-expire 10))
886886
;; Create a stale cache with only one file in it.
887887
(puthash (projectile-project-root)

0 commit comments

Comments
 (0)