.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / quick-lru / readme.md
1 # quick-lru [![Build Status](https://travis-ci.org/sindresorhus/quick-lru.svg?branch=master)](https://travis-ci.org/sindresorhus/quick-lru) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/quick-lru/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/quick-lru?branch=master)
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 [`haslru` 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
10 ## Install
11
12 ```
13 $ npm install quick-lru
14 ```
15
16
17 ## Usage
18
19 ```js
20 const QuickLRU = require('quick-lru');
21
22 const lru = new QuickLRU({maxSize: 1000});
23
24 lru.set('πŸ¦„', '🌈');
25
26 lru.has('πŸ¦„');
27 //=> true
28
29 lru.get('πŸ¦„');
30 //=> '🌈'
31 ```
32
33
34 ## API
35
36 ### new QuickLRU([options])
37
38 Returns a new instance.
39
40 ### options
41
42 Type: `Object`
43
44 #### maxSize
45
46 *Required*<br>
47 Type: `Object`
48
49 Maximum number of items before evicting the least recently used items.
50
51 ### Instance
52
53 The instance is [`iterable`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) so you can use it directly in a [`for…of`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) loop.
54
55 Both `key` and `value` can be of any type.
56
57 #### .set(key, value)
58
59 Set an item. Returns the instance.
60
61 #### .get(key)
62
63 Get an item.
64
65 #### .has(key)
66
67 Check if an item exists.
68
69 #### .peek(key)
70
71 Get an item without marking it as recently used.
72
73 #### .delete(key)
74
75 Delete an item.
76
77 #### .clear()
78
79 Delete all items.
80
81 #### .keys()
82
83 Iterable for all the keys.
84
85 #### .values()
86
87 Iterable for all the values.
88
89 #### .size
90
91 Get the item count.
92
93
94 ## License
95
96 MIT Β© [Sindre Sorhus](https://sindresorhus.com)