Cache opt

Try to address some comments from P.L.
This is the initial pull request for Theano issue #2203.