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?

5
  • 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. Commented Jun 2, 2015 at 10:13
  • I am using spacemacs, it re-defined some key mapping.
    – Daniel Wu
    Commented Jun 3, 2015 at 7: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? Commented Jun 3, 2015 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
    Commented Jun 3, 2015 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
    Commented Jul 15, 2021 at 11:01

2 Answers 2

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).

2
  • I wish there is a way to automatically do this.
    – XYZ
    Commented Dec 2, 2016 at 6: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) Commented Dec 2, 2016 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)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.