general method for caching (not used yet)