void putCache(File file, Type t) { CachedScript c = new CachedScript(); c.modified = file.modified(); c.size = file.size(); c.typeName = t.qname(); lock (m_cache) { m_cache[cacheKey(file)] = c; } }
////////////////////////////////////////////////////////////////////////// // Public ////////////////////////////////////////////////////////////////////////// public Type compile(File file, Map options) { // normalize the file path as our cache key file = file.normalize(); // unless force=true, check the cache if (!getOption(options, m_strForce, false)) { CachedScript c = getCache(file); // if cached, try to lookup type (it might have been GCed) if (c != null) { Type t1 = Type.find(c.typeName, false); if (t1 != null) { return(t1); } } } // generate a unique pod name string podName = generatePodName(file); // compile the script Pod pod = compile(podName, file, options); // get the primary type List types = pod.types(); Type t = null; for (int i = 0; i < types.sz(); ++i) { t = (Type)types.get(i); if (t.isPublic()) { break; } } if (t == null) { throw Err.make("Script file defines no public classes: " + file).val; } // put it into the cache putCache(file, t); return(t); }
//-------------------------------------------------------------------------------------------------- internal static void Add(ScriptInstance scriptInstance, List <string> fileList) { var entry = new CachedScript { Instance = scriptInstance, FileInfos = new CachedScriptFileInfo[fileList.Count], }; for (var i = 0; i < fileList.Count; i++) { var fi = new FileInfo(fileList[i]); var info = new CachedScriptFileInfo() { FileName = fileList[i], Length = fi.Length, LastWriteTime = fi.LastWriteTimeUtc }; entry.FileInfos[i] = info; } _CachedScripts[scriptInstance.Path] = entry; }
////////////////////////////////////////////////////////////////////////// // CachedScript ////////////////////////////////////////////////////////////////////////// CachedScript getCache(File file) { lock (m_cache) { // check cache string key = cacheKey(file); CachedScript c = (CachedScript)m_cache[key]; if (c == null) { return(null); } // check that timestamp and size still the same if (OpUtil.compareEQ(c.modified, file.modified()) && OpUtil.compareEQ(c.size, file.size())) { return(c); } // nuke from cache m_cache.Remove(key); return(null); } }