Skip to content

Commit bd0c761

Browse files
committed
Update readme
1 parent 4c69844 commit bd0c761

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

README.md

+17-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ A minimal JS cache. Like using an object to store keys and values, except it won
1111

1212
A plain Javascript object is often good enough for simple key-value caching.
1313

14-
The problem is that a simple object cache can grow forever. This library adds a size limit, plus `maxCacheTime` and
14+
The problem is that a plain object cache can grow forever. This library adds a size limit, plus `maxCacheTime` and
1515
smarter removal of old items.
1616

1717
## Example
@@ -23,8 +23,9 @@ const recentResults = LimitedCache({
2323
maxCacheSize: 100,
2424
});
2525
recentResults.set('abc', thingToSave);
26-
recentResults.get('abc'); // => thingToSave
27-
recentResults.has('abc'); // => true
26+
recentResults.get('abc');
27+
recentResults.has('abc');
28+
recentResults.getAll();
2829
recentResults.reset();
2930
```
3031

@@ -47,7 +48,7 @@ const cache = useLimitedCacheObject();
4748
const cache2 = useLimitedCacheObject({ maxCacheTime: 60000 }, [depsCanGoHere]);
4849
```
4950

50-
Low-level functions using plain objects, if you need to stay serializable:
51+
Low-level functions using plain objects, if you need to stay serializable or want to store offline:
5152

5253
```javascript
5354
const reduxState = {
@@ -65,6 +66,14 @@ return {
6566
};
6667
```
6768

69+
Generics for Typescript:
70+
71+
```typescript
72+
const stringCache = LimitedCache<string>();
73+
const myClassCache = useLimitedCache<SomeClass>();
74+
const offlineCacheMeta = lowLevelInit<SomeObjectShape>();
75+
```
76+
6877
## Install and Import
6978

7079
`npm install limited-cache` or `yarn add limited-cache`
@@ -109,7 +118,7 @@ These functions are grouped together as `limitedCacheUtil`. The other interfaces
109118
- `reset(cacheMeta)`
110119
- `setOptions(cacheMeta, options)` - you can update options anytime
111120

112-
You can also import these functions individually, if you want to optimize tree-shaking:
121+
You can also import these functions individually, if you want to optimize tree-shaking and minification:
113122

114123
```javascript
115124
import { lowLevelInit, lowLevelGet, lowLevelSet } from 'limited-cache';
@@ -119,11 +128,11 @@ import { lowLevelInit, lowLevelGet, lowLevelSet } from 'limited-cache';
119128

120129
**Immutable?**
121130

122-
The cache itself is, but the low-level cacheMeta is persistent.
131+
The cache itself is, but the low-level cacheMeta is persistent/mutated.
123132

124133
**API for bulk operations?**
125134

126-
Only `reset`. The other actions aren't as optimizable, so they're omitted to keep this small.
135+
Only `reset` and `getAll`. The other actions aren't as optimizable, so they're omitted to keep this small.
127136

128137
**When are old items removed?**
129138

@@ -134,4 +143,4 @@ When new items are added, or if you try to `get` an item that has expired.
134143
No: For performance it only tracks by `set` time.
135144

136145
If you want items to expire based on when they were last accessed (instead of when they were set), you can `set`
137-
the value that already exists: only the timestamp will be updated.
146+
the value that already exists: only the timestamp will be updated, so performance won't suffer.

src/core/lowLevelFunctions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
DefaultItemType,
88
} from '../types';
99

10-
// To help minimization
10+
// To help minification
1111
const {
1212
create: objectCreate,
1313
assign: objectAssign,

0 commit comments

Comments
 (0)