Smart cache

Implemented a cache that will minimize the number of queries for each call to has_user_perms.