Revert "Revert "Fixes #575. Enabled sparsity pattern caching""

This reverts commit 5a1bb1969e873725da740bc946e85a08cbfc3b44.