@creejs/commons-collection 2.0.6 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -246,6 +246,11 @@ class TimeWheelCache extends k {
246
246
  this._autoStart && this._startAutoEvict();
247
247
  }
248
248
 
249
+ get first () {
250
+ // Based on the ES6 Standard, Map keeps order of elements added
251
+ return this._cache.keys().next().value
252
+ }
253
+
249
254
  get tickInterval () {
250
255
  return this._tickInterval
251
256
  }
@@ -386,6 +391,19 @@ class TimeWheelCache extends k {
386
391
  return true
387
392
  }
388
393
 
394
+ /**
395
+ * Delete and Return the first key
396
+ * @returns {any|undefined}
397
+ */
398
+ deleteFirst () {
399
+ const firstKey = this.first;
400
+ if (firstKey == null) {
401
+ return false
402
+ }
403
+ this.delete(firstKey);
404
+ return firstKey
405
+ }
406
+
389
407
  /**
390
408
  * Checks if the cache contains the specified key.
391
409
  * @param {any} key - The key to check for existence in the cache.
@@ -529,6 +547,11 @@ class Hour24TimeWheelCache extends k {
529
547
  this._init();
530
548
  }
531
549
 
550
+ get first () {
551
+ // Based on the ES6 Standard, Map keeps order of elements added
552
+ return this._cache.keys().next().value
553
+ }
554
+
532
555
  /**
533
556
  * Max Time to Live, atom unit "millisecond"
534
557
  * @returns {number}
@@ -594,6 +617,7 @@ class Hour24TimeWheelCache extends k {
594
617
  });
595
618
 
596
619
  this._secondWheel.on('expired', (/** @type {any} */key, /** @type {any} */value, /** @type {Timestamp} */expireTimestamp) => {
620
+ this._cache.delete(key);
597
621
  this.emit(Event.Expired, key, value, expireTimestamp);
598
622
  });
599
623
  }
@@ -652,9 +676,23 @@ class Hour24TimeWheelCache extends k {
652
676
  if (!wheel) {
653
677
  return false
654
678
  }
679
+ this._cache.delete(key);
655
680
  return wheel.delete(key)
656
681
  }
657
682
 
683
+ /**
684
+ * Delete and Return the first key
685
+ * @returns {any|undefined}
686
+ */
687
+ deleteFirst () {
688
+ const firstKey = this.first;
689
+ if (firstKey == null) {
690
+ return false
691
+ }
692
+ this.delete(firstKey);
693
+ return firstKey
694
+ }
695
+
658
696
  /**
659
697
  * Checks if the cache contains the specified key.
660
698
  * @param {any} key - The key to check for existence in the cache.