@@ -37,28 +37,13 @@ public override object Get(string key, Func<object> factory)
3737 /// <inheritdoc />
3838 public object Get ( string key , Func < object > factory , TimeSpan ? timeout , bool isSliding = false , CacheItemPriority priority = CacheItemPriority . Normal , CacheItemRemovedCallback removedCallback = null , string [ ] dependentFiles = null )
3939 {
40- return Get ( key , factory , timeout , isSliding , priority , removedCallback ,
41- // NOTE: We don't want to allocate an object if it isn't going to be used so we create the CacheDependency
42- // in a callback if it's needed ... but more importantly and we didn't anticipate this, just constructing
43- // a CacheDependency object is expensive and allocates a bunch of stuff, just check the code out for it:
44- // https://referencesource.microsoft.com/#system.web/Cache/CacheDependency.cs,304
45- // Init is called as part of the ctor!! yikes.
46- // This change fixes https://github.com/umbraco/Umbraco-CMS/issues/7773
47- ( ) => dependentFiles != null && dependentFiles . Length > 0 ? new CacheDependency ( dependentFiles ) : null ) ;
40+ return GetInternal ( key , factory , timeout , isSliding , priority , removedCallback , dependentFiles ) ;
4841 }
4942
5043 /// <inheritdoc />
5144 public void Insert ( string key , Func < object > factory , TimeSpan ? timeout = null , bool isSliding = false , CacheItemPriority priority = CacheItemPriority . Normal , CacheItemRemovedCallback removedCallback = null , string [ ] dependentFiles = null )
5245 {
53-
54- Insert ( key , factory , timeout , isSliding , priority , removedCallback ,
55- // NOTE: We don't want to allocate an object if it isn't going to be used so we create the CacheDependency
56- // in a callback if it's needed ... but more importantly and we didn't anticipate this, just constructing
57- // a CacheDependency object is expensive and allocates a bunch of stuff, just check the code out for it:
58- // https://referencesource.microsoft.com/#system.web/Cache/CacheDependency.cs,304
59- // Init is called as part of the ctor!! yikes.
60- // This change fixes https://github.com/umbraco/Umbraco-CMS/issues/7773
61- ( ) => dependentFiles != null && dependentFiles . Length > 0 ? new CacheDependency ( dependentFiles ) : null ) ;
46+ InsertInternal ( key , factory , timeout , isSliding , priority , removedCallback , dependentFiles ) ;
6247 }
6348
6449 #region Dictionary
@@ -108,7 +93,7 @@ protected override void ExitWriteLock()
10893
10994 #endregion
11095
111- private object Get ( string key , Func < object > factory , TimeSpan ? timeout , bool isSliding = false , CacheItemPriority priority = CacheItemPriority . Normal , CacheItemRemovedCallback removedCallback = null , Func < CacheDependency > dependency = null )
96+ private object GetInternal ( string key , Func < object > factory , TimeSpan ? timeout , bool isSliding = false , CacheItemPriority priority = CacheItemPriority . Normal , CacheItemRemovedCallback removedCallback = null , string [ ] dependentFiles = null )
11297 {
11398 key = GetCacheKey ( key ) ;
11499
@@ -168,8 +153,12 @@ private object Get(string key, Func<object> factory, TimeSpan? timeout, bool isS
168153 var sliding = isSliding == false ? System . Web . Caching . Cache . NoSlidingExpiration : ( timeout ?? System . Web . Caching . Cache . NoSlidingExpiration ) ;
169154
170155 lck . UpgradeToWriteLock ( ) ;
156+
157+ // create a cache dependency if one is needed.
158+ var dependency = dependentFiles != null && dependentFiles . Length > 0 ? new CacheDependency ( dependentFiles ) : null ;
159+
171160 //NOTE: 'Insert' on System.Web.Caching.Cache actually does an add or update!
172- _cache . Insert ( key , result , dependency ( ) , absolute , sliding , priority , removedCallback ) ;
161+ _cache . Insert ( key , result , dependency , absolute , sliding , priority , removedCallback ) ;
173162 }
174163 }
175164
@@ -185,7 +174,7 @@ private object Get(string key, Func<object> factory, TimeSpan? timeout, bool isS
185174 return value ;
186175 }
187176
188- private void Insert ( string cacheKey , Func < object > getCacheItem , TimeSpan ? timeout = null , bool isSliding = false , CacheItemPriority priority = CacheItemPriority . Normal , CacheItemRemovedCallback removedCallback = null , Func < CacheDependency > dependency = null )
177+ private void InsertInternal ( string cacheKey , Func < object > getCacheItem , TimeSpan ? timeout = null , bool isSliding = false , CacheItemPriority priority = CacheItemPriority . Normal , CacheItemRemovedCallback removedCallback = null , string [ ] dependentFiles = null )
189178 {
190179 // NOTE - here also we must insert a Lazy<object> but we can evaluate it right now
191180 // and make sure we don't store a null value.
@@ -202,8 +191,12 @@ private void Insert(string cacheKey, Func<object> getCacheItem, TimeSpan? timeou
202191 try
203192 {
204193 _locker . EnterWriteLock ( ) ;
194+
195+ // create a cache dependency if one is needed.
196+ var dependency = dependentFiles != null && dependentFiles . Length > 0 ? new CacheDependency ( dependentFiles ) : null ;
197+
205198 //NOTE: 'Insert' on System.Web.Caching.Cache actually does an add or update!
206- _cache . Insert ( cacheKey , result , dependency ( ) , absolute , sliding , priority , removedCallback ) ;
199+ _cache . Insert ( cacheKey , result , dependency , absolute , sliding , priority , removedCallback ) ;
207200 }
208201 finally
209202 {
0 commit comments