[core] Cache permission list and remove unused middlewares

This avoids tens of SQL queries and use of useless inspects calls.