I have two servers behind a load balancer. Each server is running a memcached server and the settings file (which is identical on both servers) has them both defined (in short: shared cache).
I want the paths to the generated files to be identical on the servers so that the client does not have to download more than once.
For me to get this working I need to understand how django compressor works.
- What is the actual purpose of the cache in django compressor?
- Is the file content stored in both cache and on filesystem?
- If so, which happens first?
- I hope I’m asking the right questions here. Feel free to add some.
A more detailed and better constructed sequence than this would be very helpful.
Edit
- Since the servers both share a memcached server, should I set
COMPRESS_CACHE_KEY_FUNCTION = 'compressor.cache.socket_cachekey'(see develop branch) or does using the same cache key contribute to my point of having the same file names? - The way I understand this, mtime is collected from the source js/css files to determine if they may have changed and a new file should be generated out of them. Correct?
- This probably does not happen on each and every load. When does it happen?
If you want to have identical cache files you must be sure that you have identical input on both servers.
You should check:
{% compress %}...{% endcompress %}is identical on both servers (if you deploying to both servers at once it should be)If all of this requirements ale satisfied, generated files should be identical (content and names).
You can check mtime using “stat” unix command.
Answers to your questions:
Edit:
I have checked it on one of my websites behind load balancer. I have different file names for .css files, but they are identical for .js.
For .css files I use preprocessor (http://lesscss.org/), so it affects mtime.
Edit (after topic developed):
What is in the cache?
Due to documentation django-compressor stores in the cache two different things:
full generated code ie.:
<link rel=”stylesheet” href=”http://cdn.inprl.pl/CACHE/css/117f97d818b8.css” type=”text/css”>
Due to following cache usage django-compressor reduces number of reads to filesystem to 0. This is essential for page speed, because reading from memory is hundreds times faster than reading from filesystem. Also filesystem is very often bottleneck.
How it is stored in the cache?
django-compress is storing code in the cache using generated key. Key is generated from:
{% compress %}...{% endcompress %}{% compress %}...{% endcompress %}So those must be the same on all servers if you want to have consistent responses.
PS.
Please check constrains (like mtime) on your server and post here information if they match.
I will be fixing the same problem on my site probably next week, I will post additional details then.