@common.js/quick-lru 6.1.1 → 6.1.2
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/README.md +1 -1
- package/index.js +1 -0
- package/package.json +3 -3
- package/readme.md +0 -157
package/README.md
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
The [quick-lru](https://www.npmjs.com/package/quick-lru) package exported as CommonJS modules.
|
|
4
4
|
|
|
5
|
-
Exported from [quick-lru@6.1.
|
|
5
|
+
Exported from [quick-lru@6.1.2](https://www.npmjs.com/package/quick-lru/v/6.1.2) using https://github.com/etienne-martin/common.js.
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common.js/quick-lru",
|
|
3
|
-
"version": "6.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "6.1.2",
|
|
4
|
+
"description": "quick-lru package exported as CommonJS modules",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "etienne-martin/common.js",
|
|
7
7
|
"funding": "https://github.com/sponsors/sindresorhus",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"//test": "xo && nyc ava && tsd",
|
|
14
|
-
"test": "xo && ava
|
|
14
|
+
"test": "xo && ava"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"index.js",
|
package/readme.md
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
# quick-lru [](https://codecov.io/gh/sindresorhus/quick-lru/branch/main)
|
|
2
|
-
|
|
3
|
-
> Simple [“Least Recently Used” (LRU) cache](https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29)
|
|
4
|
-
|
|
5
|
-
Useful when you need to cache something and limit memory usage.
|
|
6
|
-
|
|
7
|
-
Inspired by the [`hashlru` algorithm](https://github.com/dominictarr/hashlru#algorithm), but instead uses [`Map`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map) to support keys of any type, not just strings, and values can be `undefined`.
|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
$ npm install quick-lru
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
|
|
17
|
-
```js
|
|
18
|
-
import QuickLRU from 'quick-lru';
|
|
19
|
-
|
|
20
|
-
const lru = new QuickLRU({maxSize: 1000});
|
|
21
|
-
|
|
22
|
-
lru.set('🦄', '🌈');
|
|
23
|
-
|
|
24
|
-
lru.has('🦄');
|
|
25
|
-
//=> true
|
|
26
|
-
|
|
27
|
-
lru.get('🦄');
|
|
28
|
-
//=> '🌈'
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## API
|
|
32
|
-
|
|
33
|
-
### new QuickLRU(options?)
|
|
34
|
-
|
|
35
|
-
Returns a new instance.
|
|
36
|
-
|
|
37
|
-
It's a [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) subclass.
|
|
38
|
-
|
|
39
|
-
### options
|
|
40
|
-
|
|
41
|
-
Type: `object`
|
|
42
|
-
|
|
43
|
-
#### maxSize
|
|
44
|
-
|
|
45
|
-
*Required*\
|
|
46
|
-
Type: `number`
|
|
47
|
-
|
|
48
|
-
The maximum number of items before evicting the least recently used items.
|
|
49
|
-
|
|
50
|
-
#### maxAge
|
|
51
|
-
|
|
52
|
-
Type: `number`\
|
|
53
|
-
Default: `Infinity`
|
|
54
|
-
|
|
55
|
-
The maximum number of milliseconds an item should remain in cache.
|
|
56
|
-
By default maxAge will be Infinity, which means that items will never expire.
|
|
57
|
-
|
|
58
|
-
Lazy expiration happens upon the next `write` or `read` call.
|
|
59
|
-
|
|
60
|
-
Individual expiration of an item can be specified by the `set(key, value, options)` method.
|
|
61
|
-
|
|
62
|
-
#### onEviction
|
|
63
|
-
|
|
64
|
-
*Optional*\
|
|
65
|
-
Type: `(key, value) => void`
|
|
66
|
-
|
|
67
|
-
Called right before an item is evicted from the cache.
|
|
68
|
-
|
|
69
|
-
Useful for side effects or for items like object URLs that need explicit cleanup (`revokeObjectURL`).
|
|
70
|
-
|
|
71
|
-
### Instance
|
|
72
|
-
|
|
73
|
-
The instance is an [`Iterable`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) of `[key, value]` pairs so you can use it directly in a [`for…of`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) loop.
|
|
74
|
-
|
|
75
|
-
Both `key` and `value` can be of any type.
|
|
76
|
-
|
|
77
|
-
#### .set(key, value, options?)
|
|
78
|
-
|
|
79
|
-
Set an item. Returns the instance.
|
|
80
|
-
|
|
81
|
-
Individual expiration of an item can be specified with the `maxAge` option. If not specified, the global `maxAge` value will be used in case it is specified on the constructor, otherwise the item will never expire.
|
|
82
|
-
|
|
83
|
-
#### .get(key)
|
|
84
|
-
|
|
85
|
-
Get an item.
|
|
86
|
-
|
|
87
|
-
#### .has(key)
|
|
88
|
-
|
|
89
|
-
Check if an item exists.
|
|
90
|
-
|
|
91
|
-
#### .peek(key)
|
|
92
|
-
|
|
93
|
-
Get an item without marking it as recently used.
|
|
94
|
-
|
|
95
|
-
#### .delete(key)
|
|
96
|
-
|
|
97
|
-
Delete an item.
|
|
98
|
-
|
|
99
|
-
Returns `true` if the item is removed or `false` if the item doesn't exist.
|
|
100
|
-
|
|
101
|
-
#### .clear()
|
|
102
|
-
|
|
103
|
-
Delete all items.
|
|
104
|
-
|
|
105
|
-
#### .resize(maxSize)
|
|
106
|
-
|
|
107
|
-
Update the `maxSize`, discarding items as necessary. Insertion order is mostly preserved, though this is not a strong guarantee.
|
|
108
|
-
|
|
109
|
-
Useful for on-the-fly tuning of cache sizes in live systems.
|
|
110
|
-
|
|
111
|
-
#### .keys()
|
|
112
|
-
|
|
113
|
-
Iterable for all the keys.
|
|
114
|
-
|
|
115
|
-
#### .values()
|
|
116
|
-
|
|
117
|
-
Iterable for all the values.
|
|
118
|
-
|
|
119
|
-
#### .entriesAscending()
|
|
120
|
-
|
|
121
|
-
Iterable for all entries, starting with the oldest (ascending in recency).
|
|
122
|
-
|
|
123
|
-
#### .entriesDescending()
|
|
124
|
-
|
|
125
|
-
Iterable for all entries, starting with the newest (descending in recency).
|
|
126
|
-
|
|
127
|
-
#### .entries()
|
|
128
|
-
|
|
129
|
-
Iterable for all entries, starting with the newest (ascending in recency).
|
|
130
|
-
|
|
131
|
-
**This method exists for `Map` compatibility. Prefer [.entriesAscending()](#entriesascending) instead.**
|
|
132
|
-
|
|
133
|
-
#### .forEach(callbackFunction, thisArgument)
|
|
134
|
-
|
|
135
|
-
Loop over entries calling the `callbackFunction` for each entry (ascending in recency).
|
|
136
|
-
|
|
137
|
-
**This method exists for `Map` compatibility. Prefer [.entriesAscending()](#entriesascending) instead.**
|
|
138
|
-
|
|
139
|
-
#### .size
|
|
140
|
-
|
|
141
|
-
The stored item count.
|
|
142
|
-
|
|
143
|
-
## Related
|
|
144
|
-
|
|
145
|
-
- [yocto-queue](https://github.com/sindresorhus/yocto-queue) - Tiny queue data structure
|
|
146
|
-
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
<div align="center">
|
|
150
|
-
<b>
|
|
151
|
-
<a href="https://tidelift.com/subscription/pkg/npm-quick-lru?utm_source=npm-quick-lru&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
|
152
|
-
</b>
|
|
153
|
-
<br>
|
|
154
|
-
<sub>
|
|
155
|
-
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
|
156
|
-
</sub>
|
|
157
|
-
</div>
|