adding cache function
Working on cache and threading
Fixing code after review
Merge pull request #8 from jakubjanuzik/bug_1945

Bug 1945