Laravel and view caching in development — can't see changes right away

后端 未结 7 1661
情深已故
情深已故 2020-12-01 14:21

Some friends and I decided to start working on a project and we came across Laravel and thought it might be a good tool. We started using it locally to develop out some of

7条回答
  •  不思量自难忘°
    2020-12-01 14:39

    It's possible this isn't a caching issue at all and doesn't have anything to do with Laravel, Apache or PHP. If you're sharing files into a Virtual Machine like Vagrant, be sure your editor is not using "Atomic Saves" when writing files.

    To test this, make a small edit (single character) to a watched file using several different text-editors. Changes saved from editors which implement atomic saves likely won't be noticed by the VM's filesystem.

    I'm editing with Sublime Text 3 on a Mac, saving files to a folder which is mounted into a Vagrant VM with NFS. Files are being watched on the local filesystem via Gulp and a livereload refresh is requested from the Vagrant host whenever a file changes.

    Changing a single character with Sublime Text 3 using the default atomic_save: true triggers a change but doesn't serve the updated file. Editing in Vim, TextEdit, Sublime Text 2 and TextWrangler all triggered updates and served the updated file contents. Switching to atomic_saves: false brings Sublime Text 3 inline with the other editors, triggering an update and serving the correct file.

    Sublime Text 3's default preferences includes this comment:

    // Save via writing to an alternate file, and then renaming it over the
    // original file.
    "atomic_save": true,
    

    The problem might have something to do with changes being written to an unwatched tempfile, then that tempfile replacing our watched file. The modification happens when the tempfile is written, not when it replaces the file we're watching, so no update is triggered. That or something with the NFS cache or VirtualBox's NFS gateway -- there's a lot of stuff in the middle.

    Many hours were wasted fiddling with opcache, Apache mods and Laravel hacks before discovering this was just an editor setting.

提交回复
热议问题