Fixed the caching

It's much more effective now. Using the memoize decorator from Flask-Cache.
Also formatted all code