示例#1
0
        public bool IsSearchPathEnumerationTool(string toolPath)
        {
            // Get the parent module (root config) if applicable. Otherwise, this is the root config so use it.
            var rootRuleSet = m_parent ?? this;

            bool result;

            if (m_searchPathEnumerationToolMatchCache.TryGetValue(toolPath, out result))
            {
                return(result);
            }

            result = false;
            foreach (var searchPathToolSuffix in rootRuleSet.m_searchPathEnumerationToolFragments)
            {
                if (toolPath.EndsWith(searchPathToolSuffix, System.StringComparison.OrdinalIgnoreCase))
                {
                    result = true;
                    break;
                }
            }

            // Cache the result
            m_searchPathEnumerationToolMatchCache.AddItem(toolPath, result);

            return(result);
        }
示例#2
0
        public static void Set(object objToWrite, string key, int?cacheDurationSeconds = null)
        {
            try
            {
                //add to mem cache
                ObjectCache.AddItem(objToWrite, key, cacheDurationSeconds);

                //write to the file system
                //(also writes to object cache)
                FileCache.AddItem(objToWrite, key, cacheDurationSeconds);

                //Is Azure Setup?
                if (Azure.IsReady)
                {
                    //writes to azure blob storage
                    //(also writes to file cache)
                    //(also writes to object cache)
                    Azure.AddItem(objToWrite, key);
                }
                //TODO: else if (AmazonS3.IsReady)
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#3
0
        public void TestParallelCacheAddGet()
        {
            var cache  = new ObjectCache <HashedKey, int>(16);
            var random = new Random(0);

            var expectedValues = new int[16 * 1024];

            for (int i = 0; i < expectedValues.Length; i++)
            {
                // Use some arbitrarily chose sampling sets to
                // give a test of interspersed hits and misses
                if ((i % 9) == 0)
                {
                    expectedValues[i] = random.Next(-5, 5);
                }
                else if ((i % 7) == 0)
                {
                    expectedValues[i] = random.Next(16, 32);
                }
                else
                {
                    expectedValues[i] = random.Next(-64, 64);
                }
            }

            // Skip zero since table cache will find HashedKey with key = 0 and hash = 0.
            // since this is equal to default(HashedKey).
            Parallel.For(
                1,
                expectedValues.Length,
                i =>
            {
                int expectedValue = expectedValues[i];

                var key = new HashedKey()
                {
                    Key  = expectedValue,
                    Hash = expectedValue
                };

                long misses = cache.Misses;
                long hits   = cache.Hits;

                int value;
                if (!cache.TryGetValue(key, out value))
                {
                    XAssert.IsTrue(cache.Misses > misses);
                    cache.AddItem(key, expectedValue);
                }
                else
                {
                    XAssert.IsTrue(cache.Hits > hits);
                    XAssert.AreEqual(expectedValue, value);
                }
            });
        }
        /// <summary>
        /// Create a directory membership filter based on the regex filter given
        /// </summary>
        public static DirectoryMembershipFilter Create(string enumeratePatternRegex)
        {
            if (enumeratePatternRegex == AllowAllRegex)
            {
                // If the regex allows all, then returns an efficient AllowAllFilter.
                return(AllowAllFilter);
            }

            RegexDirectoryMembershipFilter result;

            if (!RegexCache.TryGetValue(enumeratePatternRegex, out result))
            {
                result = new RegexDirectoryMembershipFilter(enumeratePatternRegex);
                RegexCache.AddItem(enumeratePatternRegex, result);
            }

            return(result);
        }
示例#5
0
        /// <summary>
        /// Gets a string from this table.
        /// </summary>
        public string GetString(StringId id)
        {
            Contract.Requires(id.IsValid);
            Contract.Requires(IsValid());

            if (!m_expansionCache.TryGetValue(id, out string result))
            {
                int len = GetLength(id);
                using (var wrapper = Pools.GetCharArray(len))
                {
                    char[] buffer = wrapper.Instance;
                    CopyString(id, buffer, 0);
                    result = new string(buffer, 0, len);
                    m_expansionCache.AddItem(id, result);
                }
            }

            return(result);
        }
示例#6
0
        public void TestCacheAddGet()
        {
            var cache = new ObjectCache <HashedKey, int>(16);

            long hits   = 0;
            long misses = 0;

            // Loop twice. We know that cache should still return
            // false on first TryGetValue because the entries must have
            // been evicted by the end the time the same index is reached twice
            for (int j = 0; j < 2; j++)
            {
                // Skip zero since table cache will find HashedKey with key = 0 and hash = 0.
                // since this is equal to default(HashedKey).
                for (int i = 1; i < 64; i++)
                {
                    var key = new HashedKey()
                    {
                        Key  = i,
                        Hash = i
                    };

                    int value;
                    XAssert.IsFalse(cache.TryGetValue(key, out value));
                    cache.AddItem(key, i);

                    misses++;
                    XAssert.AreEqual(hits, cache.Hits);
                    XAssert.AreEqual(misses, cache.Misses);

                    XAssert.IsTrue(cache.TryGetValue(key, out value));
                    XAssert.AreEqual(i, value);

                    hits++;
                    XAssert.AreEqual(hits, cache.Hits);
                    XAssert.AreEqual(misses, cache.Misses);
                }
            }
        }
示例#7
0
        /// <summary>
        /// Loads the cache graph store in the given directory
        /// </summary>
        public static async Task <CachedGraph> LoadAsync(string cachedGraphDirectory, LoggingContext loggingContext, bool preferLoadingEngineCacheInMemory, FileSystemStreamProvider readStreamProvider = null)
        {
            // preferLoadingEngineCacheInMemory will be removed after ExecutionLog.cs is updated in OSGTools.
            var unused = preferLoadingEngineCacheInMemory;
            CachedGraphLoader loadingGraph = CachedGraphLoader.CreateFromDisk(CancellationToken.None, cachedGraphDirectory, loggingContext, readStreamProvider);
            var graphId = await loadingGraph.GetOrLoadPipGraphIdAsync();

            // Use a the cached graph based on graph id if already in memory
            if (s_loadedCachedGraphs.TryGetValue(graphId, out var weakCachedGraph) &&
                weakCachedGraph.TryGetTarget(out var cachedGraph))
            {
                return(cachedGraph);
            }

            cachedGraph = await loadingGraph.GetOrLoadCachedGraphAsync();

            if (cachedGraph?.PipGraph != null)
            {
                s_loadedCachedGraphs.AddItem(cachedGraph.PipGraph.GraphId, new WeakReference <CachedGraph>(cachedGraph));
            }

            return(cachedGraph);
        }