Caching mechanism in CS-Script was inspired by a similar feature in Python. The concept is very simple if the script file was not modified since the last execution the compilation is not performed and the previous compilation result is used instead.
The CS-Script caching algorithm can partially support file-less scripts, which are also known as eval execution.
The following example code creates two delegates, but the code is compiled only once.
public static void Example1()
{
string script = @"double Add(double a, double b)
{
return a + b;
}";
var addInt = CSScript.Evaluator.CreateDelegate<double>(script);
var addDouble = CSScript.Evaluator.CreateDelegate<double>(script);
Console.WriteLine("Add(3, 2): {0}", addInt(3, 2));
Console.WriteLine("Add(13.5, 21.75): {0}", addDouble(13.5, 21.75));
}
By default, the caching option is enabled. You can disable it as shown below.
CSScript.CacheEnabled = false;