private function compile($file) {
        if(!file_exists($file)) {
            throw new \Exception("Could not compile $file, file not found");
        }

        if(!file_exists($this->views_cache) && !mkdir($this->views_cache)) {
            throw new \Exception("Could no create cache directory." . 
                " Make sure you have write permissions.");
        }

        $hash = md5($file);
        $compiled_file = $this->views_cache . '/' . $hash;
        $compiled = null;

        if( $this->debug || (!file_exists($compiled_file) 
            || filemtime($compiled_file) < filemtime($file))) {
            // get the katar source code and compile it
            $source = file_get_contents($file);
            $compiled = $this->compileString($source);
            $compiled = "<?php\nfunction katar_" . $hash .
                "(\$args) {\nextract(\$args);\n\$output = null;\n" . $compiled .
                "\nreturn \$output;\n}\n";

            file_put_contents($compiled_file, $compiled);
        } else {
            $compiled = file_get_contents($cache_file);
        }

        return $compiled;
    }