{"action":"created","issue":{"url":"https://api.github.com/repos/bleroy/OrchardImportTest/issues/2186","labels_url":"https://api.github.com/repos/bleroy/OrchardImportTest/issues/2186/labels{/name}","comments_url":"https://api.github.com/repos/bleroy/OrchardImportTest/issues/2186/comments","events_url":"https://api.github.com/repos/bleroy/OrchardImportTest/issues/2186/events","html_url":"https://github.com/bleroy/OrchardImportTest/issues/2186","id":66156836,"number":2186,"title":"CacheManager.Get() is not threadsafe","user":{"login":"bleroy","id":1165609,"avatar_url":"https://avatars.githubusercontent.com/u/1165609?v=3","gravatar_id":"","url":"https://api.github.com/users/bleroy","html_url":"https://github.com/bleroy","followers_url":"https://api.github.com/users/bleroy/followers","following_url":"https://api.github.com/users/bleroy/following{/other_user}","gists_url":"https://api.github.com/users/bleroy/gists{/gist_id}","starred_url":"https://api.github.com/users/bleroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bleroy/subscriptions","organizations_url":"https://api.github.com/users/bleroy/orgs","repos_url":"https://api.github.com/users/bleroy/repos","events_url":"https://api.github.com/users/bleroy/events{/privacy}","received_events_url":"https://api.github.com/users/bleroy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-04-03T14:32:45Z","updated_at":"2015-04-03T14:33:57Z","closed_at":null,"body":"If for some reason a second thread / process is hitting\n_cacheManager.Get(\"MyCacheName\", ctx => { // run some query and return the\nresult }); the following exception is raised  \n  \nA first chance exception of type 'System.NullReferenceException' occurred in\nOrchard.Framework.dll  \nSystem.NullReferenceException: Object reference not set to an instance of an\nobject.  \nat Orchard.ContentManagement.DefaultContentManager.Get(Int32 id,\nVersionOptions options) in C:\\DEVELOPMENT\\STP Frontend\\Development\\FeatureTeam\n1\\src\\Orchard\\ContentManagement\\DefaultContentManager.cs:line 149  \nat Orchard.ContentManagement.DefaultContentQuery.<Slice>b__0(ContentItemVersio\nnRecord x) in C:\\DEVELOPMENT\\STP Frontend\\Development\\FeatureTeam1\\src\\Orchard\n\\ContentManagement\\DefaultContentQuery.cs:line 141  \nat System.Linq.Enumerable.WhereSelectListIterator ` 2.MoveNext()  \nat System.Collections.Generic.List  ` 1..ctor(IEnumerable ` 1 collection)  \nat System.Linq.Enumerable.ToList[TSource](IEnumerable  ` 1 source)  \nat Orchard.Utility.Extensions.ReadOnlyCollectionExtensions.ToReadOnlyCollectio\nn[T](IEnumerable ` 1 enumerable) in C:\\DEVELOPMENT\\STP Frontend\\Development\\Fe\natureTeam1\\src\\Orchard\\Utility\\Extensions\\ReadOnlyCollectionExtensions.cs:line\n8  \nat Orchard.ContentManagement.DefaultContentQuery.Slice(Int32 skip, Int32\ncount) in C:\\DEVELOPMENT\\STP Frontend\\Development\\FeatureTeam1\\src\\Orchard\\Con\ntentManagement\\DefaultContentQuery.cs:line 139  \nat Orchard.ContentManagement.DefaultContentQuery.ContentQuery  `\n1.Orchard.ContentManagement.IContentQuery<T>.List() in C:\\DEVELOPMENT\\STP Fron\ntend\\Development\\FeatureTeam1\\src\\Orchard\\ContentManagement\\DefaultContentQuer\ny.cs:line 184  \nat Unit4.TokenService.Services.RelyingPartyService.<GetRelyingParty>b__0(Acqui\nreContext ` 1 ctx)  \nat Orchard.Caching.Cache  ` 2.CreateEntry(TKey k, Func ` 2 acquire) in\nC:\\DEVELOPMENT\\STP\nFrontend\\Development\\FeatureTeam1\\src\\Orchard\\Caching\\Cache.cs:line 57  \nat Orchard.Caching.Cache  ` 2.AddEntry(TKey k, Func ` 2 acquire) in\nC:\\DEVELOPMENT\\STP\nFrontend\\Development\\FeatureTeam1\\src\\Orchard\\Caching\\Cache.cs:line 27  \nat Orchard.Caching.Cache  ` 2.<>c__DisplayClass2.<Get>b__0(TKey k) in\nC:\\DEVELOPMENT\\STP\nFrontend\\Development\\FeatureTeam1\\src\\Orchard\\Caching\\Cache.cs:line 19  \nat System.Collections.Concurrent.ConcurrentDictionary ` 2.AddOrUpdate(TKey\nkey, Func ` 2 addValueFactory, Func ` 3 updateValueFactory)  \nat Orchard.Caching.Cache  ` 2.Get(TKey key, Func ` 2 acquire) in\nC:\\DEVELOPMENT\\STP\nFrontend\\Development\\FeatureTeam1\\src\\Orchard\\Caching\\Cache.cs:line 17  \nat Orchard.Caching.DefaultCacheManager.Get[TKey,TResult](TKey key, Func  ` 2\nacquire) in C:\\DEVELOPMENT\\STP Frontend\\Development\\FeatureTeam1\\src\\Orchard\\C\naching\\DefaultCacheManager.cs:line 33  \nat Unit4.TokenService.Services.RelyingPartyService.GetRelyingParty(String\nrealm)  \nat Unit4.TokenService.Services.RequestDetailsService.AnalyzeRelyingParty(Reque\nstDetails details)  \nat\nUnit4.TokenService.Services.RequestDetailsService.Analyze(RequestSecurityToken\nrst, IClaimsPrincipal principal)  \nat Unit4.TokenService.TokenService.GetScope(IClaimsPrincipal principal,\nRequestSecurityToken rst)  \nat Microsoft.IdentityModel.SecurityTokenService.SecurityTokenService.Issue(ICl\naimsPrincipal principal, RequestSecurityToken request)  \nat Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract.DispatchRe\nquest(DispatchContext dispatchContext)  \nat Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract.ProcessCor\ne(Message requestMessage, WSTrustRequestSerializer requestSerializer,\nWSTrustResponseSerializer responseSerializer, String requestAction, String\nresponseAction, String trustNamespace)  \n  \n  \n  \nI've a workaround, but it would be nicer if it's solved in the cachemanager or\ncacheholder  \nMy workaround is using lock on a object around each _cacheManager.Get(..) like\nthis  \n\n    \n    \n        private static object _syncLock = new object();\n    \n        public Settings.IRelyingParty GetRelyingParty(string realm)\n        {\n            lock (_syncLock)\n            {\n                var relyingParties = _cacheManager.Get(\"RelyingParties\", ctx =>\n                {\n                    ctx.Monitor(_signals.When(Signals.RelyingPartiesUpdated));\n                    return _contentManager.Query<RelyingPartyPart, RelyingPartyPartRecord>(\"RelyingParty\").List();\n                });\n                return relyingParties.FirstOrDefault(rp => string.Compare(rp.Realm, realm, true) == 0);\n            }\n        }\n\nWork Item Details\n--------------------\n**Original CodePlex Issue:**\t[Issue 18296](http://orchard.codeplex.com/workitem/18296)\n**Status:**\tClosed\n**Reason Closed:**\tUnassigned\n**Assigned to:**\tUnassigned\n**Reported on:**\tDec 19, 2011 at 1:56 PM\n**Reported by:**\trfcdejong\n**Updated on:**\tDec 22, 2011 at 7:38 PM\n**Updated by:**\tBertrandLeRoy\n**Closed on:**\tDec 22, 2011 at 7:38 PM\n**Closed by:**\tBertrandLeRoy\n**Status:**\tClosed\n**Reason Closed:**\tUnassigned\n**Assigned to:**\tUnassigned\n**Reported on:**\tDec 19, 2011 at 1:56 PM\n**Reported by:**\trfcdejong\n**Updated on:**\tDec 22, 2011 at 7:38 PM\n**Updated by:**\tBertrandLeRoy\n**Closed on:**\tDec 22, 2011 at 7:38 PM\n**Closed by:**\tBertrandLeRoy\n"},"comment":{"url":"https://api.github.com/repos/bleroy/OrchardImportTest/issues/comments/89305257","html_url":"https://github.com/bleroy/OrchardImportTest/issues/2186#issuecomment-89305257","issue_url":"https://api.github.com/repos/bleroy/OrchardImportTest/issues/2186","id":89305257,"user":{"login":"bleroy","id":1165609,"avatar_url":"https://avatars.githubusercontent.com/u/1165609?v=3","gravatar_id":"","url":"https://api.github.com/users/bleroy","html_url":"https://github.com/bleroy","followers_url":"https://api.github.com/users/bleroy/followers","following_url":"https://api.github.com/users/bleroy/following{/other_user}","gists_url":"https://api.github.com/users/bleroy/gists{/gist_id}","starred_url":"https://api.github.com/users/bleroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bleroy/subscriptions","organizations_url":"https://api.github.com/users/bleroy/orgs","repos_url":"https://api.github.com/users/bleroy/repos","events_url":"https://api.github.com/users/bleroy/events{/privacy}","received_events_url":"https://api.github.com/users/bleroy/received_events","type":"User","site_admin":false},"created_at":"2015-04-03T14:33:57Z","updated_at":"2015-04-03T14:33:57Z","body":"On *2011-12-20 02:01:24 UTC*, **@sebastienros** commented:\n\nThe CurrentSite issue was due to the Db Caching module.\n"}}