Code cleanup and cache modifications.

Cleaned up code within the core. Added application context to the generated
cache name and creation of the cache directory, if it don't exists.