33

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?

  • 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 2 '15 at 10:13
  • I am using spacemacs, it re-defined some key mapping. – Daniel Wu Jun 3 '15 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? – Kaushal Modi Jun 3 '15 at 10:44
  • 1
    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 3 '15 at 14:45
30

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

  • I wish there is a way to automatically do this. – Lorem Ipsum Dolor Dec 2 '16 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) – Jimmy Hoffa Dec 2 '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)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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