How can I make springs stretch and squeeze, depending on the cube movements?
The stretching of the springs can be accomplished through the 'stretch to' constraint. 

The motion of the cubes driven by the springs can be generated using Blender physics.

The animation, generated in Blender 2.76, uses rigid body physics to solve for the motion of the cubes and uses the 'stretch to' constraint to stretch the springs.



The steps to generate this kind of animation are:


Add three cubes to the scene. Name the cubes 'top', 'mid', 'bot'. These will be the red, green, and blue cubes in the animation.
In the physics tab, add rigid-body dynamics to each cube. Add rigid-body constraints. Setup spring constraints between each cube. For the top cube (the red one in the animation, check 'Animated'. This setup will animate the cubes moving up and down, driven by the springs.


Add 4 empties to the scene. The empties will be used to locate the ends of the spring on the cubes. Name the empties as follows: top-lower, mid-upper, mid-lower, bot-upper. These empties are placed at the upper and lower face of the cubes. The image below illustrates the placement on the bottom of a cube.


Create the spring so it aligns with the y-axis. Parent the spring to the empty on the bottom of the cube. Repeat this each cube.


Add the 'Stretch To' constraint to each spring. Chose the empty on the upper part of the cubes as the target.





Now, if the animation is started, the results should resemble the animation.




The blend file for this animation is: