projectile icon indicating copy to clipboard operation
projectile copied to clipboard

projectile-project-root's cache doesn't work as it supposed to work

Open geza-herman opened this issue 2 years ago • 1 comments

Expected behavior

Cache should work properly

Actual behavior

Cache doesn't work properly, when the project root exists, but it is found by the non-first entry of projectile-project-root-functions.

Steps to reproduce the problem

The cited part of the code doesn't use the cache properly. The problem is, if a function in projectile-project-root-functions returns nil, then this information will be lost (because there is no differentiation between "cache-entry-doesn't exist yet" and "root-not-found"). For example, suppose that the 3rd function in projectile-project-root-functions finds the root, the 1st and 2nd function returns nil. This means that the result of the 3rd function will be stored properly, but the 1st and 2nd function's result won't. Next time when projectile-project-root is called, it will try the 1st and 2nd function again (because the cache returns nil. That's a problem), and it will use the cached result for the 3rd function (this is right).

       (cl-some
        (lambda (func)
          (let* ((cache-key (format "%s-%s" func dir))
                 (cache-value (gethash cache-key projectile-project-root-cache)))
            (if (and cache-value (file-exists-p cache-value))
                cache-value
              (let ((value (funcall func (file-truename dir))))
                (puthash cache-key value projectile-project-root-cache)
                value))))
        projectile-project-root-functions)

Environment & Version information

Projectile version information

Projectile 20230228.706

geza-herman avatar Mar 27 '23 21:03 geza-herman

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed soon if no further activity occurs. Thank you for your contribution and understanding!

github-actions[bot] avatar Feb 01 '25 01:02 github-actions[bot]