@postgresx/noredis 0.7.1 → 0.8.0

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.
@@ -81,6 +81,8 @@ var PgKvCache = class {
81
81
  serializer;
82
82
  l1 = /* @__PURE__ */ new Map();
83
83
  l1Generation = 0;
84
+ l1Hits = 0;
85
+ l1Misses = 0;
84
86
  invalidationListener = null;
85
87
  invalidationReconnectUnsubscribe = null;
86
88
  constructor(options) {
@@ -287,11 +289,13 @@ var PgKvCache = class {
287
289
  WHERE ctid IN (
288
290
  SELECT ctid
289
291
  FROM ${this.quotedTableName}
290
- WHERE expires_at IS NOT NULL AND expires_at <= NOW()
291
- LIMIT $1
292
+ WHERE namespace = $1
293
+ AND expires_at IS NOT NULL
294
+ AND expires_at <= NOW()
295
+ LIMIT $2
292
296
  )
293
297
  RETURNING namespace, key`,
294
- [Math.max(1, Math.floor(limit))]
298
+ [this.namespace, Math.max(1, Math.floor(limit))]
295
299
  );
296
300
  for (const row of rows) {
297
301
  if (row.namespace === this.namespace) this.deleteL1(row.key);
@@ -595,7 +599,9 @@ var PgKvCache = class {
595
599
  namespace: this.namespace,
596
600
  tableName: this.tableName,
597
601
  l1Size: this.l1.size,
598
- l1Max: this.l1Max
602
+ l1Max: this.l1Max,
603
+ l1Hits: this.l1Hits,
604
+ l1Misses: this.l1Misses
599
605
  };
600
606
  }
601
607
  async publish(event) {
@@ -648,11 +654,16 @@ var PgKvCache = class {
648
654
  getL1(key) {
649
655
  if (!this.l1Enabled) return { hit: false };
650
656
  const entry = this.l1.get(key);
651
- if (!entry) return { hit: false };
657
+ if (!entry) {
658
+ this.l1Misses += 1;
659
+ return { hit: false };
660
+ }
652
661
  if (entry.expiresAt !== null && entry.expiresAt <= this.now()) {
653
662
  this.l1.delete(key);
663
+ this.l1Misses += 1;
654
664
  return { hit: false };
655
665
  }
666
+ this.l1Hits += 1;
656
667
  this.l1.delete(key);
657
668
  this.l1.set(key, entry);
658
669
  return { hit: true, value: entry.value };
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  PgKvCache,
11
11
  createPgKvCache
12
- } from "./chunk-BD36RDOX.js";
12
+ } from "./chunk-6D2PPDAW.js";
13
13
  import {
14
14
  PgList,
15
15
  createPgList
@@ -62,6 +62,10 @@ interface PgKvCacheStats {
62
62
  tableName: string;
63
63
  l1Size: number;
64
64
  l1Max: number;
65
+ /** Monotonic L1 read hits since the cache was created. */
66
+ l1Hits: number;
67
+ /** Monotonic L1 read misses (absent or expired) since the cache was created. */
68
+ l1Misses: number;
65
69
  }
66
70
  declare class PgKvCache {
67
71
  readonly namespace: string;
@@ -78,6 +82,8 @@ declare class PgKvCache {
78
82
  private readonly serializer;
79
83
  private readonly l1;
80
84
  private l1Generation;
85
+ private l1Hits;
86
+ private l1Misses;
81
87
  private invalidationListener;
82
88
  private invalidationReconnectUnsubscribe;
83
89
  constructor(options: PgKvCacheOptions);
package/dist/kv-cache.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PgKvCache,
3
3
  createPgKvCache
4
- } from "./chunk-BD36RDOX.js";
4
+ } from "./chunk-6D2PPDAW.js";
5
5
  export {
6
6
  PgKvCache,
7
7
  createPgKvCache
package/dist/kv.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PgKvCache,
3
3
  createPgKvCache
4
- } from "./chunk-BD36RDOX.js";
4
+ } from "./chunk-6D2PPDAW.js";
5
5
  export {
6
6
  PgKvCache,
7
7
  createPgKvCache
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postgresx/noredis",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "PostgreSQL-backed Redis feature replacement toolkit: KV/TTL cache, pub/sub, advisory locks, rate limiting, and pg-boss queues",
5
5
  "type": "module",
6
6
  "license": "MIT",