@nxtedition/cache 1.0.9 → 1.0.11

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.
package/lib/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { type MemoryOptions } from './memory.ts';
2
- export type { MemoryOptions, MemoryCacheEntry } from './memory.ts';
3
- export { MemoryCache } from './memory.ts';
2
+ export type { MemoryOptions } from './memory.ts';
4
3
  export interface DatabaseOptions {
5
4
  timeout?: number;
6
5
  maxSize?: number;
package/lib/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import { DatabaseSync, } from 'node:sqlite'
2
2
  import { MemoryCache, } from "./memory.js"
3
3
 
4
-
5
- export { MemoryCache } from './memory.ts'
4
+
6
5
 
7
6
  let fastNowTime = 0
8
7
 
@@ -173,6 +172,8 @@ export class AsyncCache {
173
172
  this.#getQuery = null
174
173
  this.#setQuery = null
175
174
  this.#delQuery = null
175
+ this.#purgeStaleQuery = null
176
+ this.#evictQuery = null
176
177
 
177
178
  process.emitWarning(err )
178
179
  break
@@ -262,7 +263,7 @@ export class AsyncCache {
262
263
  return { value: cached.value, async: false }
263
264
  }
264
265
 
265
- if (now > cached.stale) {
266
+ if (now >= cached.stale) {
266
267
  // stale-while-revalidate has expired, purge cached value.
267
268
  this.#memory?.delete(key)
268
269
  try {
@@ -313,7 +314,9 @@ export class AsyncCache {
313
314
  return value
314
315
  },
315
316
  (err) => {
316
- this.#dedupe.delete(key)
317
+ if (this.#dedupe.get(key) === promise) {
318
+ this.#dedupe.delete(key)
319
+ }
317
320
  throw err
318
321
  },
319
322
  )
package/lib/memory.js CHANGED
@@ -86,7 +86,7 @@ export class MemoryCache {
86
86
  purgeStale(now ) {
87
87
  for (let i = this.#arr.length - 1; i >= 0; i--) {
88
88
  const entry = this.#arr[i]
89
- if (now > entry.stale) {
89
+ if (now >= entry.stale) {
90
90
  this.#delete(entry)
91
91
  }
92
92
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/cache",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -28,5 +28,5 @@
28
28
  "rimraf": "^6.1.2",
29
29
  "typescript": "^5.9.3"
30
30
  },
31
- "gitHead": "0dd08f59b4d41fc8b3038386cfbd5adf970863c7"
31
+ "gitHead": "80ace3245dc851f38a288b0c3b167ca0024f0469"
32
32
  }