Rework resource caching, fix #197