Fixed bug with enabled cache

Fixed bug: If cache of Layouts enabled, handlers for custom layouts will not be added.