39

I am using spacemacs and often use the SPC p f key binding to find files in a projectile project. But even after removing a file from a git, SPC p f will show me that deleted file.

I tried using SPC p I to invalid the cache, but that didn't work.

How to resolve the problem?

Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
Daniel Wu
  • 1,711
  • 2
  • 17
  • 26
  • 4
    Can you verify that the bindings are made correctly? What do you get when you do `C-h k SPC p l`? It should be bound to `projectile-invalidate-cache`. Also check if `M-x projectile-invalidate-cache` works. – Kaushal Modi Jun 02 '15 at 10:13
  • I am using spacemacs, it re-defined some key mapping. – Daniel Wu Jun 03 '15 at 07:31
  • 2
    It's alright to change the key mapping. I am asking you to confirm if the keys are bound to the command you think should be bound. Nevertheless, did using M-x approach work? – Kaushal Modi Jun 03 '15 at 10:44
  • 2
    It was because Spacemacs uses `recentf` for sorting project files. In older Projectile version, even after you deleted the files, Projectile still reused the outdated file list from `recentf`. In later Projectile version, clearing Projectile cache also cleans up `recentf` file list and removed the deleted files. You should update to latest Projectile and try again. – Tu Do Jun 03 '15 at 14:45
  • It isn't the case in your situation, but it took me a minute to realize that the cache is based on version control (git), not the directory itself. So a deleted file will keep showing up until you stage the deletion in your VCS. – Dave Jul 15 '21 at 11:01

2 Answers2

38

Type M-x projectile-invalidate-cache and you'll see the command with the bindings listed next to it. For me the bindings said M-m p I which was correct, and should be the default I suspect for holy mode (spc p I for evil mode).

Jimmy Hoffa
  • 481
  • 4
  • 5
  • I wish there is a way to automatically do this. – XY L Dec 02 '16 at 06:13
  • 1
    @LiXinyang there's a setting you can put in your config that says to never cache project files. It however causes project operations to slow down on any project with lots of files. `'(projectile-enable-caching nil)` – Jimmy Hoffa Dec 02 '16 at 15:51
0

Inspired by @Xinyang Li question on automating cache invalidating process, I started to use snippets below to clear projectile cache for current project after I switch between projects and clear cache of all the projects after initialization of emacs.

(add-hook 'projectile-after-switch-project-hook (lambda ()
      (projectile-invalidate-cache nil)))


(add-hook 'after-init-hook (lambda ()
    (mapc (lambda (project-root)
        (remhash project-root projectile-project-type-cache)
        (remhash project-root projectile-projects-cache)
        (remhash project-root projectile-projects-cache-time)
        (when projectile-verbose
            (message "Invalidated Projectile cache for %s."
                (propertize project-root 'face 'font-lock-keyword-face)))
        (when (fboundp 'recentf-cleanup)
            (recentf-cleanup)))
        (projectile-hash-keys projectile-projects-cache))
    (projectile-serialize-cache)))
Navidot
  • 732
  • 5
  • 12