private function getCacheFolder($api, $class)
    {
        // get the api compile folder
        $compilePath = Rest::getConfig()->get($api)->CompilePath;
        if (empty($compilePath)) {
            throw new RestException('You must set CompilePath for "' . $api . '" api.');
        }
        $apiFolder = $this->str($compilePath)->trimRight('/')->append(DIRECTORY_SEPARATOR . $api);

        // get class cache folder
        $classCacheFolder = $this->str($class)->trimLeft('\\')->replace('\\', '_')->val();

        $apiFolder = $apiFolder . DIRECTORY_SEPARATOR . $classCacheFolder;

        if (!is_dir($apiFolder)) {
            mkdir($apiFolder, 0755, true);
            clearstatcache(true, realpath($apiFolder));
        }

        return $apiFolder . DIRECTORY_SEPARATOR;
    }