Cache.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. //
  2. // System.Web.Caching.Cache
  3. //
  4. // Author(s):
  5. // Lluis Sanchez ([email protected])
  6. // Marek Habersack <[email protected]>
  7. //
  8. // (C) 2005-2009 Novell, Inc (http://novell.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System.Threading;
  31. using System.Collections;
  32. using System.Security.Permissions;
  33. #if NET_2_0
  34. using System.Collections.Generic;
  35. #endif
  36. using System.Web.Configuration;
  37. namespace System.Web.Caching
  38. {
  39. // CAS - no InheritanceDemand here as the class is sealed
  40. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  41. public sealed class Cache: IEnumerable
  42. {
  43. public static readonly DateTime NoAbsoluteExpiration = DateTime.MaxValue;
  44. public static readonly TimeSpan NoSlidingExpiration = TimeSpan.Zero;
  45. #if NET_2_0 && SYSTEMCORE_DEP
  46. ReaderWriterLockSlim cacheLock;
  47. #else
  48. ReaderWriterLock cacheLock;
  49. #endif
  50. #if NET_2_0
  51. Dictionary <string, CacheItem> cache;
  52. #else
  53. Hashtable cache;
  54. #endif
  55. CacheItemPriorityQueue timedItems;
  56. Timer expirationTimer;
  57. long expirationTimerPeriod = 0;
  58. Cache dependencyCache;
  59. #if NET_2_0
  60. bool? disableExpiration;
  61. long privateBytesLimit = -1;
  62. long percentagePhysicalMemoryLimit = -1;
  63. bool DisableExpiration {
  64. get {
  65. if (disableExpiration == null) {
  66. var cs = WebConfigurationManager.GetWebApplicationSection ("system.web/caching/cache") as CacheSection;
  67. if (cs == null)
  68. disableExpiration = false;
  69. else
  70. disableExpiration = (bool)cs.DisableExpiration;
  71. }
  72. return (bool)disableExpiration;
  73. }
  74. }
  75. public long EffectivePrivateBytesLimit {
  76. get {
  77. if (privateBytesLimit == -1) {
  78. var cs = WebConfigurationManager.GetWebApplicationSection ("system.web/caching/cache") as CacheSection;
  79. if (cs == null)
  80. privateBytesLimit = 0;
  81. else
  82. privateBytesLimit = cs.PrivateBytesLimit;
  83. if (privateBytesLimit == 0) {
  84. // http://blogs.msdn.com/tmarq/archive/2007/06/25/some-history-on-the-asp-net-cache-memory-limits.aspx
  85. // TODO: calculate
  86. privateBytesLimit = 734003200;
  87. }
  88. }
  89. return privateBytesLimit;
  90. }
  91. }
  92. public long EffectivePercentagePhysicalMemoryLimit {
  93. get {
  94. if (percentagePhysicalMemoryLimit == -1) {
  95. var cs = WebConfigurationManager.GetWebApplicationSection ("system.web/caching/cache") as CacheSection;
  96. if (cs == null)
  97. percentagePhysicalMemoryLimit = 0;
  98. else
  99. percentagePhysicalMemoryLimit = cs.PercentagePhysicalMemoryUsedLimit;
  100. if (percentagePhysicalMemoryLimit == 0) {
  101. // http://blogs.msdn.com/tmarq/archive/2007/06/25/some-history-on-the-asp-net-cache-memory-limits.aspx
  102. // TODO: calculate
  103. percentagePhysicalMemoryLimit = 97;
  104. }
  105. }
  106. return percentagePhysicalMemoryLimit;
  107. }
  108. }
  109. #else
  110. bool DisableExpiration {
  111. get { return false; }
  112. }
  113. #endif
  114. public Cache ()
  115. {
  116. #if NET_2_0 && SYSTEMCORE_DEP
  117. cacheLock = new ReaderWriterLockSlim ();
  118. #else
  119. cacheLock = new ReaderWriterLock ();
  120. #endif
  121. #if NET_2_0
  122. cache = new Dictionary <string, CacheItem> (StringComparer.Ordinal);
  123. #else
  124. cache = new Hashtable ();
  125. #endif
  126. }
  127. public int Count {
  128. get { return cache.Count; }
  129. }
  130. public object this [string key] {
  131. get { return Get (key); }
  132. set { Insert (key, value); }
  133. }
  134. CacheItem GetCacheItem (string key)
  135. {
  136. if (key == null)
  137. return null;
  138. CacheItem ret;
  139. #if NET_2_0
  140. if (cache.TryGetValue (key, out ret))
  141. return ret;
  142. #else
  143. ret = cache [key] as CacheItem;
  144. if (ret != null)
  145. return ret;
  146. #endif
  147. return null;
  148. }
  149. CacheItem RemoveCacheItem (string key)
  150. {
  151. if (key == null)
  152. return null;
  153. CacheItem ret = null;
  154. #if NET_2_0
  155. if (!cache.TryGetValue (key, out ret))
  156. return null;
  157. #else
  158. ret = cache [key] as CacheItem;
  159. if (ret == null)
  160. return null;
  161. #endif
  162. ret.Disabled = true;
  163. cache.Remove (key);
  164. return ret;
  165. }
  166. public object Add (string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
  167. {
  168. if (key == null)
  169. throw new ArgumentNullException ("key");
  170. bool locked = false;
  171. try {
  172. #if NET_2_0 && SYSTEMCORE_DEP
  173. cacheLock.EnterWriteLock ();
  174. #else
  175. cacheLock.AcquireWriterLock (-1);
  176. #endif
  177. locked = true;
  178. CacheItem it = GetCacheItem (key);
  179. if (it != null)
  180. return it.Value;
  181. Insert (key, value, dependencies, absoluteExpiration, slidingExpiration, priority, onRemoveCallback, false);
  182. } finally {
  183. if (locked) {
  184. #if NET_2_0 && SYSTEMCORE_DEP
  185. cacheLock.ExitWriteLock ();
  186. #else
  187. cacheLock.ReleaseWriterLock ();
  188. #endif
  189. }
  190. }
  191. return null;
  192. }
  193. public object Get (string key)
  194. {
  195. bool locked = false;
  196. try {
  197. #if NET_2_0 && SYSTEMCORE_DEP
  198. cacheLock.EnterUpgradeableReadLock ();
  199. #else
  200. cacheLock.AcquireReaderLock (-1);
  201. #endif
  202. locked = true;
  203. CacheItem it = GetCacheItem (key);
  204. if (it == null)
  205. return null;
  206. if (it.Dependency != null && it.Dependency.HasChanged) {
  207. #if !NET_2_0
  208. LockCookie lc = default (LockCookie);
  209. #endif
  210. try {
  211. #if NET_2_0
  212. cacheLock.EnterWriteLock ();
  213. #else
  214. lc = cacheLock.UpgradeToWriterLock (-1);
  215. #endif
  216. Remove (it.Key, CacheItemRemovedReason.DependencyChanged, false);
  217. } finally {
  218. #if NET_2_0
  219. cacheLock.ExitWriteLock ();
  220. #else
  221. cacheLock.DowngradeFromWriterLock (ref lc);
  222. #endif
  223. }
  224. return null;
  225. }
  226. if (!DisableExpiration) {
  227. if (it.SlidingExpiration != NoSlidingExpiration) {
  228. it.AbsoluteExpiration = DateTime.Now + it.SlidingExpiration;
  229. // Cast to long is ok since we know that sliding expiration
  230. // is less than 365 days (31536000000ms)
  231. long remaining = (long)it.SlidingExpiration.TotalMilliseconds;
  232. it.ExpiresAt = it.AbsoluteExpiration.Ticks;
  233. if (expirationTimer != null && (expirationTimerPeriod == 0 || expirationTimerPeriod > remaining)) {
  234. expirationTimerPeriod = remaining;
  235. expirationTimer.Change (expirationTimerPeriod, expirationTimerPeriod);
  236. }
  237. } else if (DateTime.Now >= it.AbsoluteExpiration) {
  238. #if !NET_2_0
  239. LockCookie lc = default (LockCookie);
  240. #endif
  241. try {
  242. #if NET_2_0
  243. cacheLock.EnterWriteLock ();
  244. #else
  245. lc = cacheLock.UpgradeToWriterLock (-1);
  246. #endif
  247. Remove (key, CacheItemRemovedReason.Expired, false);
  248. } finally {
  249. #if NET_2_0
  250. cacheLock.ExitWriteLock ();
  251. #else
  252. cacheLock.DowngradeFromWriterLock (ref lc);
  253. #endif
  254. }
  255. return null;
  256. }
  257. }
  258. return it.Value;
  259. } finally {
  260. if (locked) {
  261. #if NET_2_0 && SYSTEMCORE_DEP
  262. cacheLock.ExitUpgradeableReadLock ();
  263. #else
  264. cacheLock.ReleaseReaderLock ();
  265. #endif
  266. }
  267. }
  268. }
  269. public void Insert (string key, object value)
  270. {
  271. Insert (key, value, null, NoAbsoluteExpiration, NoSlidingExpiration, CacheItemPriority.Normal, null, true);
  272. }
  273. public void Insert (string key, object value, CacheDependency dependencies)
  274. {
  275. Insert (key, value, dependencies, NoAbsoluteExpiration, NoSlidingExpiration, CacheItemPriority.Normal, null, true);
  276. }
  277. public void Insert (string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration)
  278. {
  279. Insert (key, value, dependencies, absoluteExpiration, slidingExpiration, CacheItemPriority.Normal, null, true);
  280. }
  281. public void Insert (string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration,
  282. CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
  283. {
  284. Insert (key, value, dependencies, absoluteExpiration, slidingExpiration, CacheItemPriority.Normal, onRemoveCallback, true);
  285. }
  286. void Insert (string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration,
  287. CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback, bool doLock)
  288. {
  289. if (key == null)
  290. throw new ArgumentNullException ("key");
  291. if (value == null)
  292. throw new ArgumentNullException ("value");
  293. if (slidingExpiration < TimeSpan.Zero || slidingExpiration > TimeSpan.FromDays (365))
  294. throw new ArgumentNullException ("slidingExpiration");
  295. if (absoluteExpiration != NoAbsoluteExpiration && slidingExpiration != NoSlidingExpiration)
  296. throw new ArgumentException ("Both absoluteExpiration and slidingExpiration are specified");
  297. CacheItem ci = new CacheItem ();
  298. ci.Value = value;
  299. ci.Key = key;
  300. if (dependencies != null) {
  301. ci.Dependency = dependencies;
  302. dependencies.DependencyChanged += new EventHandler (OnDependencyChanged);
  303. dependencies.SetCache (DependencyCache);
  304. }
  305. ci.Priority = priority;
  306. SetItemTimeout (ci, absoluteExpiration, slidingExpiration, onRemoveCallback, key, doLock);
  307. }
  308. internal void SetItemTimeout (string key, DateTime absoluteExpiration, TimeSpan slidingExpiration, bool doLock)
  309. {
  310. CacheItem ci = null;
  311. bool locked = false;
  312. try {
  313. if (doLock) {
  314. #if NET_2_0 && SYSTEMCORE_DEP
  315. cacheLock.EnterWriteLock ();
  316. #else
  317. cacheLock.AcquireWriterLock (-1);
  318. #endif
  319. locked = true;
  320. }
  321. ci = GetCacheItem (key);
  322. if (ci != null)
  323. SetItemTimeout (ci, absoluteExpiration, slidingExpiration, ci.OnRemoveCallback, null, false);
  324. } finally {
  325. if (locked) {
  326. #if NET_2_0 && SYSTEMCORE_DEP
  327. cacheLock.ExitWriteLock ();
  328. #else
  329. cacheLock.ReleaseWriterLock ();
  330. #endif
  331. }
  332. }
  333. }
  334. void SetItemTimeout (CacheItem ci, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemRemovedCallback onRemoveCallback,
  335. string key, bool doLock)
  336. {
  337. bool disableExpiration = DisableExpiration;
  338. if (!disableExpiration) {
  339. ci.SlidingExpiration = slidingExpiration;
  340. if (slidingExpiration != NoSlidingExpiration)
  341. ci.AbsoluteExpiration = DateTime.Now + slidingExpiration;
  342. else
  343. ci.AbsoluteExpiration = absoluteExpiration;
  344. }
  345. ci.OnRemoveCallback = onRemoveCallback;
  346. bool locked = false;
  347. try {
  348. if (doLock) {
  349. #if NET_2_0 && SYSTEMCORE_DEP
  350. cacheLock.EnterWriteLock ();
  351. #else
  352. cacheLock.AcquireWriterLock (-1);
  353. #endif
  354. locked = true;
  355. }
  356. if (ci.Timer != null) {
  357. ci.Timer.Dispose ();
  358. ci.Timer = null;
  359. }
  360. if (key != null)
  361. cache [key] = ci;
  362. ci.LastChange = DateTime.Now;
  363. if (!disableExpiration && ci.AbsoluteExpiration != NoAbsoluteExpiration)
  364. EnqueueTimedItem (ci);
  365. } finally {
  366. if (locked) {
  367. #if NET_2_0 && SYSTEMCORE_DEP
  368. cacheLock.ExitWriteLock ();
  369. #else
  370. cacheLock.ReleaseWriterLock ();
  371. #endif
  372. }
  373. }
  374. }
  375. // MUST be called with cache lock held
  376. void EnqueueTimedItem (CacheItem item)
  377. {
  378. long remaining = Math.Max (0, (long)(item.AbsoluteExpiration - DateTime.Now).TotalMilliseconds);
  379. item.ExpiresAt = item.AbsoluteExpiration.Ticks;
  380. if (timedItems == null)
  381. timedItems = new CacheItemPriorityQueue ();
  382. if (remaining > 4294967294)
  383. // Maximum due time for timer
  384. // Item will expire properly anyway, as the timer will be
  385. // rescheduled for the item's expiration time once that item is
  386. // bubbled to the top of the priority queue.
  387. expirationTimerPeriod = 4294967294;
  388. else
  389. expirationTimerPeriod = remaining;
  390. if (expirationTimer == null)
  391. expirationTimer = new Timer (new TimerCallback (ExpireItems), null, expirationTimerPeriod, expirationTimerPeriod);
  392. else if (expirationTimerPeriod > remaining)
  393. expirationTimer.Change (expirationTimerPeriod, expirationTimerPeriod);
  394. timedItems.Enqueue (item);
  395. }
  396. public object Remove (string key)
  397. {
  398. return Remove (key, CacheItemRemovedReason.Removed, true);
  399. }
  400. object Remove (string key, CacheItemRemovedReason reason, bool doLock)
  401. {
  402. CacheItem it = null;
  403. bool locked = false;
  404. try {
  405. if (doLock) {
  406. #if NET_2_0 && SYSTEMCORE_DEP
  407. cacheLock.EnterWriteLock ();
  408. #else
  409. cacheLock.AcquireWriterLock (-1);
  410. #endif
  411. locked = true;
  412. }
  413. it = RemoveCacheItem (key);
  414. } finally {
  415. if (locked) {
  416. #if NET_2_0 && SYSTEMCORE_DEP
  417. cacheLock.ExitWriteLock ();
  418. #else
  419. cacheLock.ReleaseWriterLock ();
  420. #endif
  421. }
  422. }
  423. if (it != null) {
  424. Timer t = it.Timer;
  425. if (t != null)
  426. t.Dispose ();
  427. if (it.Dependency != null) {
  428. #if NET_2_0
  429. it.Dependency.SetCache (null);
  430. #endif
  431. it.Dependency.DependencyChanged -= new EventHandler (OnDependencyChanged);
  432. it.Dependency.Dispose ();
  433. }
  434. if (it.OnRemoveCallback != null) {
  435. try {
  436. it.OnRemoveCallback (key, it.Value, reason);
  437. } catch {
  438. //TODO: anything to be done here?
  439. }
  440. }
  441. object ret = it.Value;
  442. it.Value = null;
  443. it.Key = null;
  444. it.Dependency = null;
  445. it.OnRemoveCallback = null;
  446. return ret;
  447. } else
  448. return null;
  449. }
  450. // Used when shutting down the application so that
  451. // session_end events are sent for all sessions.
  452. internal void InvokePrivateCallbacks ()
  453. {
  454. CacheItemRemovedReason reason = CacheItemRemovedReason.Removed;
  455. bool locked = false;
  456. try {
  457. #if NET_2_0 && SYSTEMCORE_DEP
  458. cacheLock.EnterReadLock ();
  459. #else
  460. cacheLock.AcquireReaderLock (-1);
  461. #endif
  462. locked = true;
  463. foreach (string key in cache.Keys) {
  464. CacheItem item = GetCacheItem (key);
  465. if (item.Disabled)
  466. continue;
  467. if (item != null && item.OnRemoveCallback != null) {
  468. try {
  469. item.OnRemoveCallback (key, item.Value, reason);
  470. } catch {
  471. //TODO: anything to be done here?
  472. }
  473. }
  474. }
  475. } finally {
  476. if (locked) {
  477. #if NET_2_0 && SYSTEMCORE_DEP
  478. cacheLock.ExitReadLock ();
  479. #else
  480. cacheLock.ReleaseReaderLock ();
  481. #endif
  482. }
  483. }
  484. }
  485. public IDictionaryEnumerator GetEnumerator ()
  486. {
  487. ArrayList list = new ArrayList ();
  488. bool locked = false;
  489. try {
  490. #if NET_2_0 && SYSTEMCORE_DEP
  491. cacheLock.EnterReadLock ();
  492. #else
  493. cacheLock.AcquireReaderLock (-1);
  494. #endif
  495. locked = true;
  496. #if NET_2_0
  497. foreach (CacheItem it in cache.Values)
  498. list.Add (it);
  499. #else
  500. list.AddRange (cache.Values);
  501. #endif
  502. } finally {
  503. if (locked) {
  504. #if NET_2_0 && SYSTEMCORE_DEP
  505. cacheLock.ExitReadLock ();
  506. #else
  507. cacheLock.ReleaseReaderLock ();
  508. #endif
  509. }
  510. }
  511. return new CacheItemEnumerator (list);
  512. }
  513. IEnumerator IEnumerable.GetEnumerator ()
  514. {
  515. return GetEnumerator ();
  516. }
  517. void OnDependencyChanged (object o, EventArgs a)
  518. {
  519. CheckDependencies ();
  520. }
  521. void ExpireItems (object data)
  522. {
  523. DateTime now = DateTime.Now;
  524. CacheItem item = timedItems.Peek ();
  525. while (item != null) {
  526. if (!item.Disabled && item.ExpiresAt > now.Ticks)
  527. break;
  528. if (item.Disabled)
  529. continue;
  530. item = timedItems.Dequeue ();
  531. Remove (item.Key, CacheItemRemovedReason.Expired, true);
  532. item = timedItems.Peek ();
  533. }
  534. if (item != null) {
  535. long remaining = Math.Max (0, (long)(item.AbsoluteExpiration - now).TotalMilliseconds);
  536. if (expirationTimerPeriod > remaining) {
  537. expirationTimerPeriod = remaining;
  538. expirationTimer.Change (expirationTimerPeriod, expirationTimerPeriod);
  539. }
  540. return;
  541. }
  542. expirationTimer.Change (Timeout.Infinite, Timeout.Infinite);
  543. expirationTimerPeriod = 0;
  544. }
  545. void ItemExpired(object cacheItem) {
  546. CacheItem ci = (CacheItem)cacheItem;
  547. ci.Timer.Dispose();
  548. ci.Timer = null;
  549. Remove (ci.Key, CacheItemRemovedReason.Expired, true);
  550. }
  551. internal void CheckDependencies ()
  552. {
  553. IList list;
  554. bool locked = false;
  555. try {
  556. #if NET_2_0 && SYSTEMCORE_DEP
  557. cacheLock.EnterWriteLock ();
  558. #else
  559. cacheLock.AcquireWriterLock (-1);
  560. #endif
  561. locked = true;
  562. #if NET_2_0
  563. list = new List <CacheItem> ();
  564. foreach (CacheItem it in cache.Values)
  565. list.Add (it);
  566. #else
  567. list = new ArrayList ();
  568. ((ArrayList)list).AddRange (cache.Values);
  569. #endif
  570. foreach (CacheItem it in list) {
  571. if (it.Dependency != null && it.Dependency.HasChanged)
  572. Remove (it.Key, CacheItemRemovedReason.DependencyChanged, false);
  573. }
  574. } finally {
  575. if (locked) {
  576. #if NET_2_0 && SYSTEMCORE_DEP
  577. cacheLock.ExitWriteLock ();
  578. #else
  579. cacheLock.ReleaseWriterLock ();
  580. #endif
  581. }
  582. }
  583. }
  584. internal DateTime GetKeyLastChange (string key)
  585. {
  586. bool locked = false;
  587. try {
  588. #if NET_2_0 && SYSTEMCORE_DEP
  589. cacheLock.EnterReadLock ();
  590. #else
  591. cacheLock.AcquireReaderLock (-1);
  592. #endif
  593. locked = true;
  594. CacheItem it = GetCacheItem (key);
  595. if (it == null)
  596. return DateTime.MaxValue;
  597. return it.LastChange;
  598. } finally {
  599. if (locked) {
  600. #if NET_2_0 && SYSTEMCORE_DEP
  601. cacheLock.ExitReadLock ();
  602. #else
  603. cacheLock.ReleaseReaderLock ();
  604. #endif
  605. }
  606. }
  607. }
  608. internal Cache DependencyCache {
  609. get {
  610. if (dependencyCache == null)
  611. return this;
  612. return dependencyCache;
  613. }
  614. set { dependencyCache = value; }
  615. }
  616. }
  617. }