Thursday, 15 October 2015

making squid-cache work for vagrant docker providers

squid-cache is an awesome cache that can save you tons of time while developing. For example imagine that you want to have Vagrantfile s or Dockerfile s referencing non-local repos (which is done by default). If you use docker as vagrant provider, every time you rebuild the VM (to test your overall flow), all the docker local cache gets lost. That's horrible and might mean you have to download GB's each time.

By using squid-cache, you can set it as a proxy and enable aggressive caching. To set it as a proxy, it's relevantly easy. If you use boot2docker edit /var/lib/boot2docker/profile. If you use normal Ubuntu edit /etc/default/docker. There add an http_proxy= or https_proxy= directive. By default your proxy will be something along the lines of http://10.0.2.2:3128 . Use netstat -r to find your gateway IP.

Back to squid. Squid won't be caching by default. Since you're probably downloading relavently large images they won't be cached (at least) due to being large. You have to set these two options to get them working (for 2Gb cache and max file 200Mb):

maximum_object_size 200 MB
cache_dir ufs /cygdrive/c/<my cache dir> 2000 16 256 max-size= 209715200
Keep in mind that you might have to create manually the <my cache dir> above and all the subdirectories e.g. 00/00 - 0F/FF on the previous example if you can't get "squid -z" run.

Back to squid. Another thing you might have to change compared to the default configuration is commenting out this:
#http_access deny to_localhost

Yes - in this case, it's exactly the localhost that you want to mirror.
Finally you have to update the default refresh_pattern. A more "delicate" option would be to add a few more rules for the hosts that interest you but the brute force solution would work  as well given that this is a special purpose proxy. You have to set the min-time to e.g. 10 days (14400 min).
refresh_pattern .             14400    20%        14400
As soon as you do this you should start seeing objects being cached. If you have to debug your rules a bit, set the logging (according to http://wiki.squid-cache.org/KnowledgeBase/DebugSections) to:
strip_query_terms off// This will give you info relevant to the refresh// and storage (if you need more debug info, you can set: // debug_options ALL,4). debug_options 20,4 22,4
Look on your cache.log especially for: "checking freshness of 'http://<your url>"

1 comment:

  1. 1XBET - XN Games
    1XBET online casino is 1XBET a leading content provider that is providing a range of exciting gaming content. The company 우리카지노 provides bk8 a varied gaming portfolio,

    ReplyDelete