C.R.E.A.M. – Cache Rules Everything Around Me – with vagrant-cachier

One of the challenges with using Vagrant and VirtualBox for my labs is that I run download processes over and over again. This is good for testing, but not very good for time and bandwidth usage. When we have really aggressive downloading needs like apt repository files and such, there is something that can really help with your performance on deployments and make your ISP bill much easier to deal with.

Cache is King

There is a nifty little plugin called vagrant-cachier that I use, and you may have seen it already in other builds such as the OpenStack Cookbook scripts and the Couch to OpenStack series.

To install the plugin, simply run the vagrant plugin install vagrant-cachier command like so:

cachier-install

Once your plugin is installed, we just need to put it into the Vagrantfile in order to ensure it is being used. We have a nice code block we are going to put into place towards the beginning if the Vagrantfile that will be this:


if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
config.cache.enable :apt
else
puts "[-] WARN: This would be much faster if you ran vagrant plugin install vagrant-cachier first"
end

The is just a small check to see if the plugin exists, and if it doesn’t, it will continue with the install process but warn you that cachier is not installed. The cache.scope and cache.enable option tells us the content that will be cached and the scope it will cover.

Here it is in the full Vagrantfile so that you can see where to place it:

vagrant-cachier-config

Now the next time you decide to run your apt-get dolla-dolla-bill-yall you will be saving some network bandwidth and a lot of time.

In order to really extend the use of cachier, you can visit the project page here: https://github.com/fgrehm/vagrant-cachier and you can also see the documentation here: http://fgrehm.viewdocs.io/vagrant-cachier for easy access.

There are many other configurable options that you can use, and there are more providers than just Vagrant and VirtualBox. This has become a staple for me, and I hope you get back the time and value that I have from it for your lab work.

Happy cacheing!

2 thoughts on “C.R.E.A.M. – Cache Rules Everything Around Me – with vagrant-cachier”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.