chunk-PT62335L.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import {
  2. l
  3. } from "./chunk-2Z2TG5CU.js";
  4. import {
  5. r
  6. } from "./chunk-YXWMMD76.js";
  7. // node_modules/@arcgis/core/core/MemCache.js
  8. var s = -3;
  9. var i;
  10. !function(t) {
  11. t[t.ALL = 0] = "ALL", t[t.SOME = 1] = "SOME";
  12. }(i || (i = {}));
  13. var r2 = class {
  14. constructor(t, e, s2) {
  15. this._namespace = t, this._storage = e, this._removeFunc = false, this._hit = 0, this._miss = 0, this._storage.register(this), this._namespace += ":", s2 && (this._storage.registerRemoveFunc(this._namespace, s2), this._removeFunc = true);
  16. }
  17. destroy() {
  18. this._storage.clear(this._namespace), this._removeFunc && this._storage.deregisterRemoveFunc(this._namespace), this._storage.deregister(this), this._storage = null;
  19. }
  20. get namespace() {
  21. return this._namespace.slice(0, -1);
  22. }
  23. get hitRate() {
  24. return this._hit / (this._hit + this._miss);
  25. }
  26. get size() {
  27. return this._storage.size;
  28. }
  29. get maxSize() {
  30. return this._storage.maxSize;
  31. }
  32. resetHitRate() {
  33. this._hit = this._miss = 0;
  34. }
  35. put(t, e, s2, i2 = 0) {
  36. this._storage.put(this._namespace + t, e, s2, i2);
  37. }
  38. get(t) {
  39. const e = this._storage.get(this._namespace + t);
  40. return void 0 === e ? ++this._miss : ++this._hit, e;
  41. }
  42. pop(t) {
  43. const e = this._storage.pop(this._namespace + t);
  44. return void 0 === e ? ++this._miss : ++this._hit, e;
  45. }
  46. updateSize(t, e, s2) {
  47. this._storage.updateSize(this._namespace + t, e, s2);
  48. }
  49. clear() {
  50. this._storage.clear(this._namespace);
  51. }
  52. clearAll() {
  53. this._storage.clearAll();
  54. }
  55. getStats() {
  56. return this._storage.getStats();
  57. }
  58. resetStats() {
  59. this._storage.resetStats();
  60. }
  61. };
  62. var h = class {
  63. constructor(t = 10485760) {
  64. this._maxSize = t, this._db = /* @__PURE__ */ new Map(), this._size = 0, this._hit = 0, this._miss = 0, this._removeFuncs = new l(), this._users = new l();
  65. }
  66. destroy() {
  67. this.clearAll(), this._removeFuncs.clear(), this._users.clear(), this._db = null;
  68. }
  69. register(t) {
  70. this._users.push(t);
  71. }
  72. deregister(t) {
  73. this._users.removeUnordered(t);
  74. }
  75. registerRemoveFunc(t, e) {
  76. this._removeFuncs.push([t, e]);
  77. }
  78. deregisterRemoveFunc(t) {
  79. this._removeFuncs.filterInPlace((e) => e[0] !== t);
  80. }
  81. get size() {
  82. return this._size;
  83. }
  84. get maxSize() {
  85. return this._maxSize;
  86. }
  87. set maxSize(t) {
  88. this._maxSize = Math.max(t, 0), this._checkSizeLimit();
  89. }
  90. put(t, e, r3, h2) {
  91. const _ = this._db.get(t);
  92. if (_ && (this._size -= _.size, this._db.delete(t), _.entry !== e && this._notifyRemove(t, _.entry, i.ALL)), r3 > this._maxSize)
  93. return void this._notifyRemove(t, e, i.ALL);
  94. if (void 0 === e)
  95. return void console.warn("Refusing to cache undefined entry ");
  96. if (!r3 || r3 < 0)
  97. return void console.warn("Refusing to cache entry with invalid size " + r3);
  98. const o = 1 + Math.max(h2, s) - s;
  99. this._db.set(t, { entry: e, size: r3, lifetime: o, lives: o }), this._size += r3, this._checkSizeLimit();
  100. }
  101. updateSize(e, s2, r3) {
  102. const h2 = this._db.get(e);
  103. if (h2 && h2.entry === s2) {
  104. for (this._size -= h2.size; r3 > this._maxSize; ) {
  105. const h3 = this._notifyRemove(e, s2, i.SOME);
  106. if (!(r(h3) && h3 > 0))
  107. return void this._db.delete(e);
  108. r3 = h3;
  109. }
  110. h2.size = r3, this._size += r3, this._checkSizeLimit();
  111. }
  112. }
  113. pop(t) {
  114. const e = this._db.get(t);
  115. if (e)
  116. return this._size -= e.size, this._db.delete(t), ++this._hit, e.entry;
  117. ++this._miss;
  118. }
  119. get(t) {
  120. const e = this._db.get(t);
  121. if (void 0 !== e)
  122. return this._db.delete(t), e.lives = e.lifetime, this._db.set(t, e), ++this._hit, e.entry;
  123. ++this._miss;
  124. }
  125. getStats() {
  126. const t = { Size: Math.round(this._size / 1048576) + "/" + Math.round(this._maxSize / 1048576) + "MB", "Hit rate": Math.round(100 * this._getHitRate()) + "%", Entries: this._db.size.toString() }, e = {}, i2 = new Array();
  127. this._db.forEach((t2, s2) => {
  128. const r4 = t2.lifetime;
  129. i2[r4] = (i2[r4] || 0) + t2.size, this._users.forAll((i3) => {
  130. const r5 = i3.namespace;
  131. if (s2.startsWith(r5)) {
  132. const s3 = e[r5] || 0;
  133. e[r5] = s3 + t2.size;
  134. }
  135. });
  136. });
  137. const r3 = {};
  138. this._users.forAll((t2) => {
  139. const s2 = t2.namespace;
  140. if (!isNaN(t2.hitRate) && t2.hitRate > 0) {
  141. const i3 = e[s2] || 0;
  142. e[s2] = i3, r3[s2] = Math.round(100 * t2.hitRate) + "%";
  143. } else
  144. r3[s2] = "0%";
  145. });
  146. const h2 = Object.keys(e);
  147. h2.sort((t2, s2) => e[s2] - e[t2]), h2.forEach((s2) => t[s2] = Math.round(e[s2] / 2 ** 20) + "MB / " + r3[s2]);
  148. for (let _ = i2.length - 1; _ >= 0; --_) {
  149. const e2 = i2[_];
  150. e2 && (t["Priority " + (_ + s - 1)] = Math.round(e2 / this.size * 100) + "%");
  151. }
  152. return t;
  153. }
  154. resetStats() {
  155. this._hit = this._miss = 0, this._users.forAll((t) => t.resetHitRate());
  156. }
  157. clear(t) {
  158. this._db.forEach((e, s2) => {
  159. s2.startsWith(t) && (this._size -= e.size, this._db.delete(s2), this._notifyRemove(s2, e.entry, i.ALL));
  160. });
  161. }
  162. clearAll() {
  163. this._db.forEach((t, e) => this._notifyRemove(e, t.entry, i.ALL)), this._size = 0, this._db.clear();
  164. }
  165. _getHitRate() {
  166. return this._hit / (this._hit + this._miss);
  167. }
  168. _notifyRemove(t, e, s2) {
  169. let i2;
  170. return this._removeFuncs.some((r3) => {
  171. if (t.startsWith(r3[0])) {
  172. const t2 = r3[1](e, s2);
  173. return "number" == typeof t2 && (i2 = t2), true;
  174. }
  175. return false;
  176. }), i2;
  177. }
  178. _checkSizeLimit() {
  179. if (!(this._size <= this._maxSize))
  180. for (const [e, s2] of this._db) {
  181. if (this._db.delete(e), s2.lives <= 1) {
  182. this._size -= s2.size;
  183. const r3 = this._notifyRemove(e, s2.entry, i.SOME);
  184. r(r3) && r3 > 0 && (this._size += r3, s2.lives = s2.lifetime, s2.size = r3, this._db.set(e, s2));
  185. } else
  186. --s2.lives, this._db.set(e, s2);
  187. if (this._size <= 0.9 * this.maxSize)
  188. return;
  189. }
  190. }
  191. };
  192. export {
  193. r2 as r,
  194. h
  195. };
  196. //# sourceMappingURL=chunk-PT62335L.js.map