예제 #1
0
        private static bool TryGetDiskCacheResult(string source, string name, InMemoryRavenConfiguration configuration, out string indexFilePath,
                                                  out Type type)
        {
            // It's not in the in-memory cache. See if it's been cached on disk.
            //
            // Q. Why do we cache on disk?
            // A. It decreases the duration of individual test runs. Instead of
            //    recompiling the index each test run, we can just load them from disk.
            //    It also decreases creation time for indexes that were
            //    previously created and deleted, affecting both production and test environments.
            //
            // For more info, see http://ayende.com/blog/161218/robs-sprint-idly-indexing?key=f37cf4dc-0e5c-43be-9b27-632f61ba044f#comments-form-location
            var indexCacheDir = GetIndexCacheDir(configuration);

            string sourceHashed;

            using (var md5 = MD5.Create())
            {
                var hash = md5.ComputeHash(Encoding.UTF8.GetBytes(source));
                sourceHashed = MonoHttpUtility.UrlEncode(Convert.ToBase64String(hash));
            }
            indexFilePath = Path.Combine(indexCacheDir,
                                         IndexingUtil.StableInvariantIgnoreCaseStringHash(source) + "." + sourceHashed + "." +
                                         (Debugger.IsAttached ? "debug" : "nodebug") + ".dll");

            try
            {
                if (Directory.Exists(indexCacheDir) == false)
                {
                    Directory.CreateDirectory(indexCacheDir);
                }
                type = TryGetIndexFromDisk(indexFilePath, name);
            }
            catch (UnauthorizedAccessException)
            {
                // permission issues
                type = null;
                return(false);
            }
            catch (IOException)
            {
                // permission issues, probably
                type = null;
                return(false);
            }

            if (type != null)
            {
                cacheEntries.TryAdd(source, new CacheEntry
                {
                    Source = source,
                    Type   = type,
                    Usages = 1
                });
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        private static string GetIndexFilePath(string source, string indexCacheDir)
        {
            var hash          = Encryptor.Current.Hash.Compute16(Encoding.UTF8.GetBytes(source));
            var sourceHashed  = MonoHttpUtility.UrlEncode(Convert.ToBase64String(hash));
            var indexFilePath = Path.Combine(indexCacheDir,
                                             IndexingUtil.StableInvariantIgnoreCaseStringHash(source) + "." + sourceHashed + "." +
                                             (Debugger.IsAttached ? "debug" : "nodebug") + ".dll");

            return(indexFilePath);
        }
예제 #3
0
        private static string GetIndexFilePath(string source, string indexCacheDir, out int numberHash)
        {
            var hash = Hashing.XXHash64.CalculateRaw(source);

            var sourceHashed = hash.ToString("X");

            numberHash = IndexingUtil.StableInvariantIgnoreCaseStringHash(source);
            var indexFilePath = Path.Combine(indexCacheDir,
                                             numberHash + "." + sourceHashed + "." +
                                             (Debugger.IsAttached ? "debug" : "nodebug") + ".dll");

            return(indexFilePath);
        }