Use APC if loaded for storing cache

as a fallback save serialized array to a file
also fixed some cgl issues