有没有办法保存 LINQPad.Util.Compile 的结果并在很长一段时间内重新运行它

Is there a way to save the results of LINQPad.Util.Compile and rerun it over long periods of time

我有一个脚本 Web 服务,可以从内容管理系统下载和 运行 linqpad .linq 程序。我目前正在做类似下面代码的事情。有没有办法保存 LINQPad.Util.Compile 的结果并将其存储在某个地方,以便我可以使用它直到 .linq 文件发生更改?现在我觉得它每次都在重新编译,并产生许多编译文件夹。

public static object DownloadAndRunScript(string scriptFilePath, object args)
{
     var compiledScript = LINQPad.Util.Compile(scriptFilePath, true);
     var queryExecutorResult = compiledScript.Run(LINQPad.QueryResultFormat.Text, args);
     return (object)queryExecutorResult.ReturnValue;
}

您可以很容易地为此编写一个缓存函数。像这样:

static Dictionary<string, Tuple<DateTime, QueryCompilation>> _cache
    = new Dictionary<string, System.Tuple<System.DateTime, QueryCompilation>>();

public static QueryCompilation GetCompilation (string scriptFilePath)
{
    Tuple<DateTime, LINQPad.ObjectModel.QueryCompilation> entry;
    var writeTime = new FileInfo (scriptFilePath).LastWriteTimeUtc;

    lock (_cache)
        if (_cache.TryGetValue (scriptFilePath, out entry) && entry.Item1 == writeTime)
            return entry.Item2;

    var compiledScript = LINQPad.Util.Compile (scriptFilePath, true);

    lock (_cache)
        _cache [scriptFilePath] = Tuple.Create (writeTime, compiledScript);

    return compiledScript;
}