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.
A more detailed and better constructed sequence than this would be very helpful.
Edit
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?In the develop branch there is a new option to change the css hashing method. https://github.com/jezdez/django_compressor
See line 61 in filters/css_default.py
The settings I'm using:
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = False
COMPRESS_STORAGE = 'compressor.storage.GzipCompressorFileStorage'
COMPRESS_CSS_HASHING_METHOD = 'hash' # not using mtime since it differs between servers.
There is no option like this for js files since their hash key is never generated using mtime anyway.
This works perfectly behind my loadbalancer.
When this is written, the following is the latest commit in the develop branch: https://github.com/jezdez/django_compressor/commit/d48bc5f45d5a55b0f826eb605ccf09a6bf33fcb9
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With