ObjectCacheSettings.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.Runtime.Collections
  5. {
  6. class ObjectCacheSettings
  7. {
  8. int cacheLimit;
  9. TimeSpan idleTimeout;
  10. TimeSpan leaseTimeout;
  11. int purgeFrequency;
  12. const int DefaultCacheLimit = 64;
  13. const int DefaultPurgeFrequency = 32;
  14. static TimeSpan DefaultIdleTimeout = TimeSpan.FromMinutes(2);
  15. static TimeSpan DefaultLeaseTimeout = TimeSpan.FromMinutes(5);
  16. public ObjectCacheSettings()
  17. {
  18. this.CacheLimit = DefaultCacheLimit;
  19. this.IdleTimeout = DefaultIdleTimeout;
  20. this.LeaseTimeout = DefaultLeaseTimeout;
  21. this.PurgeFrequency = DefaultPurgeFrequency;
  22. }
  23. ObjectCacheSettings(ObjectCacheSettings other)
  24. {
  25. this.CacheLimit = other.CacheLimit;
  26. this.IdleTimeout = other.IdleTimeout;
  27. this.LeaseTimeout = other.LeaseTimeout;
  28. this.PurgeFrequency = other.PurgeFrequency;
  29. }
  30. internal ObjectCacheSettings Clone()
  31. {
  32. return new ObjectCacheSettings(this);
  33. }
  34. public int CacheLimit
  35. {
  36. get
  37. {
  38. return this.cacheLimit;
  39. }
  40. set
  41. {
  42. Fx.Assert(value >= 0, "caller should validate cache limit is non-negative");
  43. this.cacheLimit = value;
  44. }
  45. }
  46. public TimeSpan IdleTimeout
  47. {
  48. get
  49. {
  50. return this.idleTimeout;
  51. }
  52. set
  53. {
  54. Fx.Assert(value >= TimeSpan.Zero, "caller should validate cache limit is non-negative");
  55. this.idleTimeout = value;
  56. }
  57. }
  58. public TimeSpan LeaseTimeout
  59. {
  60. get
  61. {
  62. return this.leaseTimeout;
  63. }
  64. set
  65. {
  66. Fx.Assert(value >= TimeSpan.Zero, "caller should validate cache limit is non-negative");
  67. this.leaseTimeout = value;
  68. }
  69. }
  70. public int PurgeFrequency
  71. {
  72. get
  73. {
  74. return this.purgeFrequency;
  75. }
  76. set
  77. {
  78. Fx.Assert(value >= 0, "caller should validate purge frequency is non-negative");
  79. this.purgeFrequency = value;
  80. }
  81. }
  82. }
  83. }