public static function path($filename)
    {
        if ($filename[0] != "/") {
            $filename = static::$path . "/" . $filename;
        }

        if (substr($filename, -5) != ".json") {
            $filename .= ".json";
        }

        $path = pathinfo($filename, PATHINFO_DIRNAME);

        # Ensure the cache directory exists
        if (!is_dir($path)) {
            if (!mkdir($path, 0777, true)) {
                throw new \Exception("Unable to create cache directory (" . $path . ")");
            }
        }

        # Ensure directory is writable
        if (!is_writable($path)) {
            if (!chmod($path, 0777)) {
                throw new \Exception("Cache directory (" . $path . ") is not writable");
            }
        }

        return $filename;
    }