Hi, Maybe i have misunderstood something but i find the cache mechanism for directory local variables unreliable in one rare case. If first .dir-locals.el is read and a binding say foo = 1 is inserted in the dir-locals-directory-cache. And then foo = 2 is written in the same second. Now next time the dir locals the old binding foo = 1 will be returned. The cache entry is considered valid when it should not. Of course it is unlikely that a user is typing so fast that they trigger this :). But it can be triggered from Lisp. I found out when playing with a ert test case that was tampering with a dir local. Here is a recipe for this: (defvar foo nil) (put 'foo 'safe-local-variable 'numberp) (let ((dir (make-temp-file "cache-test" t))) ;; Create .dir-locals.el with foo = 1. (with-temp-buffer (cd dir) (add-dir-local-variable nil 'foo 1) (save-buffer) (kill-buffer)) ;; Read it into dir-locals-directory-cache ;; and save .dir-locals.el with foo = 2. (with-temp-buffer (cd dir) (make-local-variable 'foo) (hack-dir-local-variables-non-file-buffer) (add-dir-local-variable nil 'foo 2) (save-buffer) (kill-buffer)) ;; Read it back again. ;; It should be 2 at this point but is 1 most of the times. ;; (At the rare occasion that seconds increase ;; between the two add-dir-local-variable it returns 1). (with-temp-buffer (cd dir) (make-local-variable 'foo) (hack-dir-local-variables-non-file-buffer) (delete-file dir-locals-file) (delete-directory dir) foo)) The current mechanism: The bindings found when reading a .dir-locals.el file is put into dir-locals-directory-cache. The mtime of the file is stored in the cache entry. Later a cache entry is considered valid if it's mtime equals that of the file-attribute mtime of corresponding .dir-locals.el file. Suggestion: The mtime stored in the cache entry should be the time when .dir-local.el was read into memory. A cache entry should be considered valid if mtime of cache entry is greater than the file-attribute mtime of corresponding .dir-locals.el file. This will invalidate a couple of entries that should ideally have been considered valid but it will not let through any invalid ones. Or it should not let through any invalid entries, but in fact it seem to do so sometimes. If the above test is looped it will return the incorrect value one time in about 500 on my standard Ubuntu GNU/Linux system. I don't know why, maybe reading the mtime from a file is not that reliable. Anyway, to be on the safe side i subtract one second from the mtime when storing it to the cache. Now the test ran 50000 times with no trouble. Attached is a patch for files.el with this modification. If this makes sense and is accepted i will update the patch with the appropriate documentation changes as well. Regards, /Johan