Add caching to weighted networks

Fixes #102.