コード例 #1
0
        public static async Task HandelCachedOnGetAsync(CacheScope scope)
        {
            var services       = scope.ServiceProvider.GetService <ServiceLocator>();
            var viewStatistics = scope.RequestData.To <IViewStatistic[]>();

            await updateViewStatisticAsync(services.DbUpdator, false, viewStatistics);
        }
コード例 #2
0
ファイル: Router.cs プロジェクト: xen2/msbuild
        /// <summary>
        /// This method creates a BuildResult using the information contained in a completed build request and
        /// then routes it to the right node. On a child process, this means either consume the result localy,
        /// or send it to the parent node. On a parent node, this means either consume the result locally or
        /// send it to a child node
        /// </summary>
        internal void PostDoneNotice(BuildRequest buildRequest)
        {
            // Create a container with the results of the evaluation
            BuildResult buildResult = buildRequest.GetBuildResult();

            // If we're supposed to use caching and this request wasn't restored from cache, cache it
            if (buildRequest.UseResultsCache && !buildRequest.RestoredFromCache)
            {
                CacheScope cacheScope = parentEngine.CacheManager.GetCacheScope(buildRequest.ProjectFileName, buildRequest.GlobalProperties, buildRequest.ToolsetVersion, CacheContentType.BuildResults);
                cacheScope.AddCacheEntryForBuildResults(buildResult);
            }

            // an external request is any request that came from the parent engine, all requests to a child are external
            // unless the project was alredy loaded on the node itself
            if (buildRequest.IsExternalRequest)
            {
                // If the build request was send from outside the current process,
                // send the results to the parent engine
                parentNode.PostBuildResultToHost(buildResult);
            }
            else
            {
                // In the case of a child process, getting to this point means the request will be satisfied locally, the node index should be 0
                // on the parent engine however, the node index can be, 0 for the local node, or can be >0 which represents a child node
                PostDoneNotice(buildRequest.NodeIndex, buildResult);
            }
        }
コード例 #3
0
        public void Initialize()
        {
            // Create some items and place them in a dictionary
            // Add some include information so that when we check the final
            // item spec we can verify that the item was recreated properly
            BuildItem buildItem1 = new BuildItem("BuildItem1", "Item1");

            buildItem1.Include = "TestInclude1";
            BuildItem[] buildItems = new BuildItem[1];
            buildItems[0] = buildItem1;
            Dictionary <object, object> dictionary = new Dictionary <object, object>();

            dictionary.Add("TaskItems", buildItems);

            Hashtable resultByTargetSuccess = new Hashtable(StringComparer.OrdinalIgnoreCase);

            resultByTargetSuccess.Add("TaskItems", Target.BuildState.CompletedSuccessfully);
            Hashtable resultByTargetFailure = new Hashtable(StringComparer.OrdinalIgnoreCase);

            resultByTargetFailure.Add("TaskItems", Target.BuildState.CompletedUnsuccessfully);
            Hashtable resultByTargetSkipped = new Hashtable(StringComparer.OrdinalIgnoreCase);

            resultByTargetSkipped.Add("TaskItems", Target.BuildState.Skipped);

            resultWithOutputs = new BuildResult(dictionary, resultByTargetSuccess, true, 1, 1, 3, true, string.Empty, string.Empty, 0, 0, 0);
            failedResult      = new BuildResult(dictionary, resultByTargetFailure, false, 1, 1, 3, true, string.Empty, string.Empty, 0, 0, 0);
            uncacheableResult = new BuildResult(dictionary, resultByTargetSkipped, true, 1, 1, 3, true, string.Empty, string.Empty, 0, 0, 0);

            cacheScope = new CacheScope("temp.proj", new BuildPropertyGroup(), "3.5");
        }
コード例 #4
0
ファイル: CacheManager_Tests.cs プロジェクト: yxbdali/msbuild
        public void CheckBasicOperation()
        {
            CacheManager cacheManager = new CacheManager("3.5");
            CacheScope   cacheScope   = cacheManager.GetCacheScope("Test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.Items);

            Assert.IsNotNull(cacheScope, "Cache should not have an entry");
            CacheScope cacheScope1 = cacheManager.GetCacheScope("Test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.Items);

            Assert.AreEqual(cacheScope, cacheScope1, "Expected to get the same scope");
            cacheScope1 = cacheManager.GetCacheScope("Test1.proj", new BuildPropertyGroup(), "3.5", CacheContentType.Items);
            Assert.IsNotNull(cacheScope1, "Cache should not have an entry");
            Assert.AreNotEqual(cacheScope, cacheScope1, "Expected to get different scopes");
            // Add an entry and verify that it ends up in the right scope
            CacheEntry cacheEntry  = new BuildResultCacheEntry("TestEntry", null, true);
            CacheEntry cacheEntry1 = new BuildResultCacheEntry("TestEntry1", null, true);

            cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "Test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.Items);
            Assert.IsNotNull(cacheScope.GetCacheEntry("TestEntry"), "Cache should have an entry");
            Assert.IsNotNull(cacheManager.GetCacheEntries(new string[] { "TestEntry" }, "Test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.Items)[0],
                             "Cache should have an entry");
            cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry1 }, "Test1.proj", new BuildPropertyGroup(), "3.5", CacheContentType.Items);
            Assert.IsNotNull(cacheScope1.GetCacheEntry("TestEntry1"), "Cache should have an entry");
            Assert.IsNotNull(cacheManager.GetCacheEntries(new string[] { "TestEntry1" }, "Test1.proj", new BuildPropertyGroup(), "3.5", CacheContentType.Items)[0],
                             "Cache should have an entry");
            // Try clearing the whole cache
            cacheManager.ClearCache();
            Assert.AreNotEqual(cacheScope, cacheManager.GetCacheScope("Test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.Items),
                               "Expected to get different scopes");
        }
コード例 #5
0
ファイル: Router.cs プロジェクト: xen2/msbuild
        /// <summary>
        /// This method is called once the engine has decided to sent a build request to a child node.
        /// Route the given BuildRequest to the given node. If necessary a routing context is
        /// created to manage future communication with the node regarding the build request.
        /// </summary>
        internal void PostBuildRequest(BuildRequest currentRequest, int nodeIndex)
        {
            // if the request is to be sent to the parent node, post the request back to the host
            if (nodeIndex == EngineCallback.parentNode)
            {
                ParentNode.PostBuildRequestToHost(currentRequest);
            }
            else
            {
                // Dont create any contexts if the request was supposed to be processed on the current node
                if (nodeIndex != EngineCallback.inProcNode)
                {
                    // Get the cache scope for the request (possibly creating it). The cache scope will contain the taskoutputs of the build request
                    // which can be reused of the same project/toolsversion/globalproperties is asked for again.
                    CacheScope cacheScope = parentEngine.CacheManager.GetCacheScope(currentRequest.ProjectFileName, currentRequest.GlobalProperties, currentRequest.ToolsetVersion, CacheContentType.BuildResults);

                    // Create a routing context and update the request to refer to the new node handle id
                    int parentHandleId = currentRequest.HandleId;
                    currentRequest.HandleId =
                        parentEngine.EngineCallback.CreateRoutingContext
                            (nodeIndex, currentRequest.HandleId, currentRequest.NodeIndex,
                            currentRequest.RequestId, cacheScope, currentRequest, null);



                    // Check to see if we need to change the traversal strategy of the system
                    // parentHandleId and node index are not used in the function so it can be ignored
                    scheduler?.NotifyOfBuildRequest(nodeIndex, currentRequest, parentHandleId);


                    nodeManager.PostBuildRequestToNode(nodeIndex, currentRequest);
                }
            }
        }
コード例 #6
0
 public void Reset(List <Entity> entities, Cache <Entity> entityCache, CacheScope componentCache)
 {
     _entities       = entities;
     _entityCache    = entityCache;
     _componentCache = componentCache;
     _newEntities.Clear();
     _removedEntities.Clear();
 }
コード例 #7
0
 public LinkHcoCacheEntryConfiguration(
     CacheScope cacheScope,
     DateTimeOffset?localExpirationDate)
     : this(hasConfiguration : true)
 {
     CacheScope          = cacheScope;
     LocalExpirationDate = localExpirationDate;
 }
コード例 #8
0
 public LinkHcoCacheEntry(
     string linkResponseContent,
     CacheScope cacheScope,
     DateTimeOffset?localExpirationDate)
 {
     LinkResponseContent = linkResponseContent;
     CacheScope          = cacheScope;
     LocalExpirationDate = localExpirationDate;
 }
コード例 #9
0
 protected LinkHcoCacheEntry CreateEntry(
     string content,
     CacheScope scope)
 {
     return(new LinkHcoCacheEntry(
                content,
                scope,
                null));
 }
コード例 #10
0
ファイル: CacheManager_Tests.cs プロジェクト: yxbdali/msbuild
        public void TestClearCacheScope()
        {
            CacheManager cacheManager = new CacheManager("3.5");
            CacheScope   cacheScope   = cacheManager.GetCacheScope("test.proj", new BuildPropertyGroup(), null, CacheContentType.BuildResults);

            cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.defaultTargetCacheName, "Target1;Target2"));
            cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.initialTargetCacheName, "Initial1"));
            cacheManager.ClearCacheScope("test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults);
            Assert.AreNotEqual(cacheScope, cacheManager.GetCacheScope("test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults), "Expected to get different scopes");
        }
コード例 #11
0
ファイル: WebCacheManager.cs プロジェクト: cairabbit/daf
 public ICacheProvider CreateCacheProvider(CacheScope scope)
 {
     switch (scope)
     {
         case CacheScope.WorkUnit:
             return new RequestCacheProvider();
         case CacheScope.Global:
         default:
             return new WebCacheProvider();
     }
 }
コード例 #12
0
 public HttpLinkHcoCacheEntryConfiguration(
     CacheScope cacheScope,
     DateTimeOffset?localExpirationDate,
     CacheMode cacheMode,
     string etag,
     DateTimeOffset?lastModified)
     : base(cacheScope, localExpirationDate)
 {
     CacheMode    = cacheMode;
     ETag         = etag;
     LastModified = lastModified;
 }
コード例 #13
0
        public ICacheProvider CreateCacheProvider(CacheScope scope)
        {
            switch (scope)
            {
            case CacheScope.WorkUnit:
                return(new RequestCacheProvider());

            case CacheScope.Global:
            default:
                return(new WebCacheProvider());
            }
        }
コード例 #14
0
ファイル: CacheManager_Tests.cs プロジェクト: yxbdali/msbuild
        public void TestRequestCachingDefaultInitialTargets()
        {
            CacheManager cacheManager = new CacheManager("3.5");

            ArrayList  actuallyBuiltTargets;
            CacheScope cacheScope = cacheManager.GetCacheScope("test.proj", new BuildPropertyGroup(), null, CacheContentType.BuildResults);

            cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.defaultTargetCacheName, "Target1;Target2"));
            cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.initialTargetCacheName, "Initial1"));
            cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.projectIdCacheName, "5"));

            CacheEntry cacheEntry = new BuildResultCacheEntry("Initial1", null, true);

            cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults);
            cacheEntry = new BuildResultCacheEntry("Target1", null, true);
            cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), null, CacheContentType.BuildResults);
            cacheEntry = new BuildResultCacheEntry("Target2", null, false);
            cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults);
            cacheEntry = new BuildResultCacheEntry("Target3", null, true);
            cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), null, CacheContentType.BuildResults);

            // Default target
            BuildRequest defaultRequest = new BuildRequest(1, "test.proj", null, new BuildPropertyGroup(), null, 1, true, false);
            BuildResult  buildResult    = cacheManager.GetCachedBuildResult(defaultRequest, out actuallyBuiltTargets);

            Assert.IsNotNull(buildResult, "Expect a cached value if scope contains data");

            Assert.AreEqual(3, actuallyBuiltTargets.Count);
            Assert.AreEqual("Initial1", actuallyBuiltTargets[0]);
            Assert.AreEqual("Target1", actuallyBuiltTargets[1]);
            Assert.AreEqual("Target2", actuallyBuiltTargets[2]);
            Assert.AreEqual(3, buildResult.ResultByTarget.Count);
            Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Initial1"]);
            Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Target1"]);
            Assert.AreEqual(Target.BuildState.CompletedUnsuccessfully, buildResult.ResultByTarget["Target2"]);
            Assert.AreEqual(false, buildResult.EvaluationResult);
            Assert.AreEqual(5, buildResult.ProjectId);

            // Specific target
            BuildRequest specificRequest = new BuildRequest(1, "test.proj", new string[] { "Target3" }, new BuildPropertyGroup(), null, 1, true, false);

            buildResult = cacheManager.GetCachedBuildResult(specificRequest, out actuallyBuiltTargets);
            Assert.IsNotNull(buildResult, "Expect a cached value if scope contains data");

            Assert.AreEqual(2, actuallyBuiltTargets.Count);
            Assert.AreEqual("Initial1", actuallyBuiltTargets[0]);
            Assert.AreEqual("Target3", actuallyBuiltTargets[1]);
            Assert.AreEqual(2, buildResult.ResultByTarget.Count);
            Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Initial1"]);
            Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Target3"]);
            Assert.AreEqual(true, buildResult.EvaluationResult);
            Assert.AreEqual(5, buildResult.ProjectId);
        }
コード例 #15
0
ファイル: CacheScope_Tests.cs プロジェクト: enricosada/sln
        public void TestConstructor()
        {
            BuildPropertyGroup default_scope = new BuildPropertyGroup(new Project());

            Assertion.AssertNotNull(default_scope);

            CacheScope testScope = new CacheScope("Test.proj", default_scope, "2.0");

            Assert.AreEqual(testScope.ScopeProperties, default_scope, "Expected ScopeProperties to be set");

            // We should have detached the parent project from the property group, to avoid holding on to it in the cache
            Assertion.AssertEquals(null, testScope.ScopeProperties.ParentProject);
        }
コード例 #16
0
 public HttpLinkHcoCacheEntry(
     string linkResponseContent,
     CacheScope cacheScope,
     DateTimeOffset?localExpirationDate,
     CacheMode cacheMode,
     string etag,
     DateTimeOffset?lastModified)
     : base(linkResponseContent, cacheScope, localExpirationDate)
 {
     CacheMode    = cacheMode;
     ETag         = etag;
     LastModified = lastModified;
 }
コード例 #17
0
 public static Accessor Instance(CacheScope cs) 
 { 
     if (cs == null)
         return g_Instance;
     lock(cs)
     {
         object acc = cs.Get(typeof (Accessor));
         if (acc != null)
         {
             return acc as Accessor;
         }
         Accessor ret = CreateInstance<Accessor>();
         ret.m_CS = cs;
         cs.Add(typeof(Accessor), ret);
         return ret;
     }
 }
コード例 #18
0
ファイル: CacheScope_Tests.cs プロジェクト: enricosada/sln
        public void BasicCacheOperation()
        {
            BuildPropertyGroup default_scope = new BuildPropertyGroup();
            CacheScope         testScope     = new CacheScope("Test.proj", new BuildPropertyGroup(), "2.0");
            // First add a single entry and verify that it is in the cache
            CacheEntry cacheEntry = new BuildResultCacheEntry("TestEntry", null, true);

            testScope.AddCacheEntry(cacheEntry);
            Assert.IsTrue(testScope.ContainsCacheEntry("TestEntry"), "Expect entry in the cache");
            CacheEntry inCacheEntry = testScope.GetCacheEntry("TestEntry");

            Assert.IsNotNull(inCacheEntry, "Cache should have an entry");
            Assert.IsTrue(inCacheEntry.IsEquivalent(cacheEntry), "Expect entry to be the same");
            // Add a second entry and then remove the first entry. Verify that the first entry
            // is not in the cache while the second entry is still there
            cacheEntry = new BuildResultCacheEntry("TestEntry2", null, true);
            testScope.AddCacheEntry(cacheEntry);
            testScope.ClearCacheEntry("TestEntry");
            Assert.IsFalse(testScope.ContainsCacheEntry("TestEntry"), "Didn't expect entry in the cache");
            Assert.IsTrue(testScope.ContainsCacheEntry("TestEntry2"), "Expected entry in the cache");
            Assert.IsNull(testScope.GetCacheEntry("TestEntry"), "Cache should  not have an entry");
            Assert.IsNotNull(testScope.GetCacheEntry("TestEntry2"), "Cache should have an entry");
        }
コード例 #19
0
ファイル: CacheScope_Tests.cs プロジェクト: enricosada/sln
        public void AddRemoveBuildResults()
        {
            BuildPropertyGroup default_scope = new BuildPropertyGroup();
            CacheScope         testScope     = new CacheScope("Test.proj", new BuildPropertyGroup(), "2.0");

            // First add a single empty result (expect no crash)
            testScope.AddCacheEntryForBuildResults(resultWith0Outputs);
            // Add a single result - expect to find target in the cache
            testScope.AddCacheEntryForBuildResults(resultWith1Outputs);
            Assert.IsTrue(testScope.ContainsCacheEntry("Target1"), "Expected entry in the cache");
            Assert.IsNotNull(testScope.GetCacheEntry("Target1"), "Cache should have an entry");
            // Add a double result expect both target in the entry
            testScope.AddCacheEntryForBuildResults(resultWith2Outputs);
            Assert.IsTrue(testScope.ContainsCacheEntry("Target2"), "Expected entry in the cache");
            Assert.IsNotNull(testScope.GetCacheEntry("Target2"), "Cache should have an entry");
            Assert.IsTrue(testScope.ContainsCacheEntry("Target3"), "Expected entry in the cache");
            Assert.IsNotNull(testScope.GetCacheEntry("Target3"), "Cache should have an entry");
            // Double add a result ( expect no crash since it is identical )
            testScope.AddCacheEntryForBuildResults(resultWith1Outputs);
            // Add an uncacheable result and verify that it is not in the cache
            testScope.AddCacheEntryForBuildResults(uncacheableResult);
            Assert.IsFalse(testScope.ContainsCacheEntry("Target4"), "Didn't expect entry in the cache");
            Assert.IsNull(testScope.GetCacheEntry("Target4"), "Cache should  not have an entry");
        }
コード例 #20
0
 public EntitySet(Cache <Entity> entityCache, CacheScope componentCache, CacheScope getCache)
 {
     _entityCache    = entityCache;
     _componentCache = componentCache;
     _getCache       = getCache;
 }
コード例 #21
0
ファイル: CacheManager_Tests.cs プロジェクト: yxbdali/msbuild
        public void TestRequestCaching()
        {
            CacheManager cacheManager = new CacheManager("3.5");

            ArrayList actuallyBuiltTargets;

            // Test the case where we pass in null targets
            Dictionary <string, string> dictionary = new Dictionary <string, string>();
            BuildRequest emptyRequest = new BuildRequest(1, "test.proj", null, dictionary, null, 1, true, false);

            Assert.IsNull(cacheManager.GetCachedBuildResult(emptyRequest, out actuallyBuiltTargets), "Expect a null return value if T=null");

            // Test the case where we pass in length 0 targets
            BuildRequest length0Request = new BuildRequest(1, "test.proj", new string[0], dictionary, null, 1, true, false);

            Assert.IsNull(cacheManager.GetCachedBuildResult(length0Request, out actuallyBuiltTargets), "Expect a null return value if T.Length=0");

            // Test the case when the scope doesn't exist
            string[]     targets        = new string[1]; targets[0] = "Target1";
            BuildRequest length1Request = new BuildRequest(1, "test.proj", targets, new BuildPropertyGroup(), null, 1, true, false);

            Assert.IsNull(cacheManager.GetCachedBuildResult(length1Request, out actuallyBuiltTargets), "Expect a null return value if no scope");

            // Test the case when the scope exists but is empty
            CacheScope cacheScope = cacheManager.GetCacheScope("test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults);

            Assert.IsNull(cacheManager.GetCachedBuildResult(length1Request, out actuallyBuiltTargets), "Expect a null return value if scope is empty");

            // Test the case when the scope exists but contains wrong data
            CacheEntry cacheEntry = new BuildResultCacheEntry("Target2", null, true);

            cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults);
            Assert.IsNull(cacheManager.GetCachedBuildResult(length1Request, out actuallyBuiltTargets), "Expect a null return value if scope contains wrong data");

            // Test the case when everything is correct
            cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.defaultTargetCacheName, string.Empty));
            cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.initialTargetCacheName, string.Empty));
            cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.projectIdCacheName, "1"));

            cacheEntry = new BuildResultCacheEntry("Target1", null, true);
            cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults);
            BuildResult buildResult = cacheManager.GetCachedBuildResult(length1Request, out actuallyBuiltTargets);

            Assert.IsNotNull(buildResult, "Expect a cached value if scope contains data");
            Assert.AreEqual(1, actuallyBuiltTargets.Count);
            Assert.AreEqual("Target1", actuallyBuiltTargets[0]);
            Assert.AreEqual(1, buildResult.ResultByTarget.Count);
            Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Target1"]);

            // Test the case when the scope contains partially correct data
            targets = new string[2]; targets[0] = "Target2"; targets[1] = "Target3";
            BuildRequest length2Request = new BuildRequest(1, "test.proj", targets, new BuildPropertyGroup(), null, 1, true, false);

            Assert.IsNull(cacheManager.GetCachedBuildResult(length2Request, out actuallyBuiltTargets), "Expect a null return value if partial data in the scope");

            // Test the correctness case for multiple targets
            cacheEntry = new BuildResultCacheEntry("Target3", null, true);
            cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults);
            buildResult = cacheManager.GetCachedBuildResult(length2Request, out actuallyBuiltTargets);
            Assert.IsNotNull(buildResult, "Expect a cached value if scope contains data");

            Assert.AreEqual(2, actuallyBuiltTargets.Count);
            Assert.AreEqual("Target2", actuallyBuiltTargets[0]);
            Assert.AreEqual("Target3", actuallyBuiltTargets[1]);
            Assert.AreEqual(2, buildResult.ResultByTarget.Count);
            Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Target2"]);
            Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Target3"]);
            Assert.AreEqual(1, buildResult.ProjectId);
        }
コード例 #22
0
        public static HttpLinkHcoCacheEntryConfiguration FromHttpResponse(
            HttpResponseMessage response,
            DateTimeOffset assumedNow)
        {
            var cc = response.Headers.CacheControl;

            if (cc is null)
            {
                return(new HttpLinkHcoCacheEntryConfiguration(false));
            }

            CacheMode      mode           = CacheMode.Undefined;
            CacheScope     scope          = CacheScope.Undefined;
            string         etag           = string.Empty;
            DateTimeOffset?lastModified   = null;
            DateTimeOffset?expirationDate = null;

            if (cc.MustRevalidate)
            {
                mode = CacheMode.RevalidateStale;
            }
            if (cc.NoCache)
            {
                mode = CacheMode.AlwaysRevalidate;
            }
            if (cc.NoStore)
            {
                mode = CacheMode.DoNotCache;
            }

            if (cc.Public)
            {
                scope = CacheScope.AcrossUserContexts;
            }
            if (cc.Private)
            {
                scope = CacheScope.ForIndividualUserContext;
            }

            if (cc.MaxAge != null)
            {
                expirationDate = assumedNow + cc.MaxAge.Value;
            }
            if (!string.IsNullOrEmpty(response.Headers.ETag?.Tag))
            {
                etag = StringHelpers.RemoveSurroundingQuotes(response.Headers.ETag.Tag);
            }

            if (response.Content.Headers.LastModified != null)
            {
                lastModified = response.Content.Headers.LastModified.Value;
            }

            var hasImplicitCacheMode =
                scope != CacheScope.Undefined ||
                !string.IsNullOrEmpty(etag) ||
                lastModified != null ||
                expirationDate != null;

            if (hasImplicitCacheMode)
            {
                if (mode == CacheMode.Undefined)
                {
                    mode = CacheMode.NoRevalidationRequired;
                }
            }

            if (mode != CacheMode.Undefined)
            {
                return(new HttpLinkHcoCacheEntryConfiguration(
                           scope,
                           expirationDate,
                           mode,
                           etag,
                           lastModified));
            }

            return(new HttpLinkHcoCacheEntryConfiguration(false));
        }
コード例 #23
0
 internal void Init(CacheScope componentCache)
 {
     _componentCache = componentCache;
 }
コード例 #24
0
 public object Get(string key, CacheScope scope)
 {
     return(CacheService.Get(string.Format("{0}:{1}", key, SPCoreService.UserId), scope));
 }
コード例 #25
0
 public void Put(string key, object data, CacheScope scope, string[] tags)
 {
     CacheService.Put(string.Format("{0}:{1}", key, SPCoreService.UserId), data, scope, tags);
 }
コード例 #26
0
 public CacheAttribute(CacheScope scope, long expiredTime = 0)
 {
     this.Scope       = scope;
     this.ExpiredTime = expiredTime;
 }
コード例 #27
0
 public void Remove(string key, CacheScope scope)
 {
     CacheService.Remove(string.Format("{0}:{1}", key, SPCoreService.UserId), scope);
 }
コード例 #28
0
 internal EntityCollection(List <Entity> entities, CacheScope cache)
 {
     _entities = entities;
     _cache    = cache;
 }
コード例 #29
0
 public void RemoveByTags(string[] tags, CacheScope scope)
 {
     CacheService.RemoveByTags(tags, scope);
 }
コード例 #30
0
 public EntitySet()
 {
     _entityCache    = new Cache <Entity>();
     _componentCache = new CacheScope();
     _getCache       = new CacheScope();
 }