Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: isaacs/node-lru-cache
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v10.1.0
Choose a base ref
...
head repository: isaacs/node-lru-cache
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v10.2.0
Choose a head ref
  • 2 commits
  • 4 files changed
  • 2 contributors

Commits on Jan 25, 2024

  1. Implement the Map interface

    PR-URL: #326
    Credit: @alexgleason
    Close: #326
    Reviewed-by: @isaacs
    alexgleason authored and isaacs committed Jan 25, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1fb1167 View commit details
  2. 10.2.0

    isaacs committed Jan 25, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c7dd17f View commit details
Showing with 16 additions and 6 deletions.
  1. +4 −0 CHANGELOG.md
  2. +2 −2 package-lock.json
  3. +1 −1 package.json
  4. +9 −3 src/index.ts
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# cringe lorg

## 10.2.0

- types: implement the `Map<K, V>` interface

## 10.1.0

- add `cache.info(key)` to get value as well as ttl and size
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lru-cache",
"description": "A cache object that deletes the least-recently-used items.",
"version": "10.1.0",
"version": "10.2.0",
"author": "Isaac Z. Schlueter <i@izs.me>",
"keywords": [
"mru",
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -812,7 +812,7 @@ export namespace LRUCache {
* Changing any of these will alter the defaults for subsequent method calls,
* but is otherwise safe.
*/
export class LRUCache<K extends {}, V extends {}, FC = unknown> {
export class LRUCache<K extends {}, V extends {}, FC = unknown> implements Map<K,V> {
// properties coming in from the options of these, only max and maxSize
// really *need* to be protected. The rest can be modified, as they just
// set defaults for various methods.
@@ -1392,7 +1392,7 @@ export class LRUCache<K extends {}, V extends {}, FC = unknown> {
this.#keyList[i] !== undefined &&
!this.#isBackgroundFetch(this.#valList[i])
) {
yield [this.#keyList[i], this.#valList[i]]
yield [this.#keyList[i], this.#valList[i]] as [K, V]
}
}
}
@@ -1460,7 +1460,7 @@ export class LRUCache<K extends {}, V extends {}, FC = unknown> {
v !== undefined &&
!this.#isBackgroundFetch(this.#valList[i])
) {
yield this.#valList[i]
yield this.#valList[i] as V
}
}
}
@@ -1491,6 +1491,12 @@ export class LRUCache<K extends {}, V extends {}, FC = unknown> {
return this.entries()
}

/**
* A String value that is used in the creation of the default string description of an object.
* Called by the built-in method Object.prototype.toString.
*/
[Symbol.toStringTag] = 'LRUCache'

/**
* Find a value for which the supplied fn method returns a truthy value,
* similar to Array.find(). fn is called as fn(value, key, cache).