Exemple #1
0
        private IUnresolvedAssembly LoadAssemblyWithCache(string filename)
        {
            var key           = new FileInfo(filename).FullName;
            var lastWriteTime = File.GetLastWriteTime(filename);
            var asm           = Dictionary.TryGetValue(key);

            if (asm == null || asm.LastWriteTime != lastWriteTime)
            {
                asm = new NAssemblyCacheItem
                {
                    UnresolvedAssembly = LoadAssembly(filename),
                    LastWriteTime      = lastWriteTime,
                    Filename           = filename,
                    Key     = key,
                    LastHit = DateTime.Now,
                    Hits    = 1,
                };
                Put(asm);
            }
            asm.LastHit = DateTime.Now;
            asm.Hits++;

            if (IdleTimeToClear.TotalMilliseconds > 0)
            {
                IdleTimer.Change(IdleTimeToClear, TimeSpan.FromMilliseconds(-1));
            }

            return(asm.UnresolvedAssembly);
        }
Exemple #2
0
 private void Put(NAssemblyCacheItem asm)
 {
     Dictionary[asm.Key] = asm;
     CleanupIfOverMaxItems();
 }