aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@toptal.com>2026-04-27 01:27:35 +0000
committerBozhidar Batsov <bozhidar@toptal.com>2026-04-27 01:27:35 +0000
commita55eeb2b1821c5252a5ea3d8c7c79728a42763fe (patch)
tree9d31b39e0aa4a9821232eceb790d4894c13d77ba /test
parent67c18e26fe68552a273b7794451ce757cc3afe9a (diff)
Seed cache time when loading the project file cache from disk
Without this, `projectile-files-cache-expire' combined with persistent caching ended up re-reading the cache file from disk on every call to `projectile-project-files' and never reindexing: the TTL check at the top of `projectile-project-files' evicts the in-memory entry whenever its cache time is missing, and `projectile-load-project-cache' was populating only `projectile-projects-cache' on disk loads. Use the cache file's mtime as the recorded time, so the TTL check sees a real age and reindexing happens when (and only when) the data is actually stale.
Diffstat (limited to 'test')
-rw-r--r--test/projectile-test.el26
1 files changed, 25 insertions, 1 deletions
diff --git a/test/projectile-test.el b/test/projectile-test.el
index 52c3b98..e21effb 100644
--- a/test/projectile-test.el
+++ b/test/projectile-test.el
@@ -3300,7 +3300,31 @@ projectile-process-current-project-buffers-current to have similar behaviour"
(spy-on 'file-exists-p :and-return-value t)
(spy-on 'projectile-unserialize :and-return-value nil)
(projectile-load-project-cache "/project/")
- (expect (gethash "/project/" projectile-projects-cache) :to-be nil))))
+ (expect (gethash "/project/" projectile-projects-cache) :to-be nil)))
+ (it "records a cache time so TTL checks don't immediately evict the loaded data"
+ ;; Without this, `projectile-files-cache-expire' combined with persistent
+ ;; caching would re-read the cache file from disk on every call (and never
+ ;; reindex), because the TTL check evicts entries that have no recorded time.
+ (projectile-test-with-sandbox
+ (projectile-test-with-files
+ ("project/")
+ (let ((cache-file (expand-file-name "project/.projectile-cache.eld"))
+ (projectile-projects-cache (make-hash-table :test 'equal))
+ (projectile-projects-cache-time (make-hash-table :test 'equal)))
+ (with-temp-file cache-file
+ (insert (prin1-to-string '("file1.el" "file2.el"))))
+ (spy-on 'projectile-project-cache-file :and-return-value cache-file)
+ (projectile-load-project-cache "/project/")
+ (expect (gethash "/project/" projectile-projects-cache)
+ :to-equal '("file1.el" "file2.el"))
+ (expect (gethash "/project/" projectile-projects-cache-time)
+ :to-be-truthy)
+ (expect (gethash "/project/" projectile-projects-cache-time)
+ :to-equal
+ (time-convert
+ (file-attribute-modification-time
+ (file-attributes cache-file))
+ 'integer)))))))
(describe "projectile-project-buffer-p"
(it "uses the truename cache when provided"