@creejs/commons-collection 2.0.6 → 2.0.7

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.
@@ -242,6 +242,11 @@ class TimeWheelCache extends k {
242
242
  this._autoStart && this._startAutoEvict();
243
243
  }
244
244
 
245
+ get first () {
246
+ // Based on the ES6 Standard, Map keeps order of elements added
247
+ return this._cache.keys().next().value
248
+ }
249
+
245
250
  get tickInterval () {
246
251
  return this._tickInterval
247
252
  }
@@ -382,6 +387,19 @@ class TimeWheelCache extends k {
382
387
  return true
383
388
  }
384
389
 
390
+ /**
391
+ * Delete and Return the first key
392
+ * @returns {any|undefined}
393
+ */
394
+ deleteFirst () {
395
+ const firstKey = this.first;
396
+ if (firstKey == null) {
397
+ return false
398
+ }
399
+ this.delete(firstKey);
400
+ return firstKey
401
+ }
402
+
385
403
  /**
386
404
  * Checks if the cache contains the specified key.
387
405
  * @param {any} key - The key to check for existence in the cache.
@@ -525,6 +543,11 @@ class Hour24TimeWheelCache extends k {
525
543
  this._init();
526
544
  }
527
545
 
546
+ get first () {
547
+ // Based on the ES6 Standard, Map keeps order of elements added
548
+ return this._cache.keys().next().value
549
+ }
550
+
528
551
  /**
529
552
  * Max Time to Live, atom unit "millisecond"
530
553
  * @returns {number}
@@ -590,6 +613,7 @@ class Hour24TimeWheelCache extends k {
590
613
  });
591
614
 
592
615
  this._secondWheel.on('expired', (/** @type {any} */key, /** @type {any} */value, /** @type {Timestamp} */expireTimestamp) => {
616
+ this._cache.delete(key);
593
617
  this.emit(Event.Expired, key, value, expireTimestamp);
594
618
  });
595
619
  }
@@ -648,9 +672,23 @@ class Hour24TimeWheelCache extends k {
648
672
  if (!wheel) {
649
673
  return false
650
674
  }
675
+ this._cache.delete(key);
651
676
  return wheel.delete(key)
652
677
  }
653
678
 
679
+ /**
680
+ * Delete and Return the first key
681
+ * @returns {any|undefined}
682
+ */
683
+ deleteFirst () {
684
+ const firstKey = this.first;
685
+ if (firstKey == null) {
686
+ return false
687
+ }
688
+ this.delete(firstKey);
689
+ return firstKey
690
+ }
691
+
654
692
  /**
655
693
  * Checks if the cache contains the specified key.
656
694
  * @param {any} key - The key to check for existence in the cache.