Don Rhummy
Don Rhummy

Reputation: 25810

Apache (not the browser) is caching my file

The browser is not caching it. It gets the response headers:

Accept-Ranges:bytes
Cache-Control:max-age=0, no-cache, no-store, must-revalidate
Connection:Keep-Alive
Content-Length:425169
Content-Type:application/javascript
Date:Thu, 09 Mar 2017 20:06:53 GMT
Expires:Wed, 11 Jan 1984 05:00:00 GMT
Keep-Alive:timeout=5, max=100
Last-Modified:Thu, 09 Mar 2017 20:06:49 GMT
Pragma:no-cache
Server:Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16

My settings in Apache:

<VirtualHost *:80>
    <Directory "/webapps/apps/devsite">
        Allow from all
        AllowOverride All
        Order allow,deny
    </Directory>
    DocumentRoot /webapps/apps/devsite
    ServerName testing.devsite.com
    SSLEngine off
</VirtualHost>

My .htaccess:

<FilesMatch "\.(html|htm|js|css)$">
FileETag None
<IfModule mod_headers.c>
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</IfModule>
</FilesMatch> 

The following loads a new, non-cached version:

  1. on the server run: rm -f /webapps/apps/devsite/scripts/script.js
  2. Reload in the web browser (thus getting a 404)
  3. Copy the file back on to server
  4. Reload in browser

The following does loads an old, CACHED version!:

  1. On the server run: rm -f /webapps/apps/devsite/scripts/script.js
  2. Copy the file back on to server (NOTE: I did not reload in browser yet)
  3. Reload in browser

This shows that Apache is somehow caching it until it gets a new request and cannot find it. Why? How do i fix this?

Upvotes: 2

Views: 2147

Answers (2)

Don Rhummy
Don Rhummy

Reputation: 25810

The issue was it was using the kernel's SendFile which caused it to miss the file being changed. This is a Virtual Machine shared folder. Adding the following fixes it:

EnableSendfile off

(the "file" is lowercase)

More info here: https://www.vagrantup.com/docs/synced-folders/virtualbox.html

http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile

Upvotes: 1

Daniel W.
Daniel W.

Reputation: 32260

Apache does not permanently watch all files, only when you request a specific resource.

When you hit the 404 error, Apache loses the information about the file it has had found before.

The last modified timestamp does not change when you don't request a resource in the meantime.

Upvotes: 0

Related Questions