Skip to content

Commit

Permalink
Update readme (#23)
Browse files Browse the repository at this point in the history
* Update readme

* Update docs/notes
  • Loading branch information
spautz authored Jun 14, 2020
1 parent 55cf158 commit ba65946
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ All notable changes to this project will be documented in this file. See [standa

## [0.4.1](https://github.com/spautz/limited-cache/compare/v0.4.0...v0.4.1) (2020-06-13)

- Update devDependencies: No changes expected
> Update devDependencies for security, update configs for dev tools
- No changes expected in limited-cache itself

## [0.4.0](https://github.com/spautz/limited-cache/compare/v0.3.0...v0.4.0) (2020-03-14)

- Update devDependencies: No changes expected
> Update devDependencies, the build system, and the package distribution
- No changes expected in limited-cache itself

## [0.3.0](https://github.com/spautz/limited-cache/compare/v0.2.1...v0.3.0) (2020-02-19)

Expand Down
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A minimal JS cache. Like using an object to store keys and values, except it won

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

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

## Example
Expand All @@ -23,8 +23,9 @@ const recentResults = LimitedCache({
maxCacheSize: 100,
});
recentResults.set('abc', thingToSave);
recentResults.get('abc'); // => thingToSave
recentResults.has('abc'); // => true
recentResults.get('abc');
recentResults.has('abc');
recentResults.getAll();
recentResults.reset();
```

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

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

```javascript
const reduxState = {
Expand All @@ -65,6 +66,14 @@ return {
};
```

Typescript generics, if you want to define types for items in the cache:

```typescript
const stringCache = LimitedCache<string>();
const myClassCache = useLimitedCache<SomeClass>();
const offlineCacheMeta = lowLevelInit<SomeObjectShape>();
```

## Install and Import

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

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

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

**Immutable?**

The cache itself is, but the low-level cacheMeta is persistent.
The cache itself is, but the low-level cacheMeta is persistent/mutated.

**API for bulk operations?**

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

**When are old items removed?**

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

If you want items to expire based on when they were last accessed (instead of when they were set), you can `set`
the value that already exists: only the timestamp will be updated.
the value that already exists: only the timestamp will be updated, so performance won't suffer.
2 changes: 1 addition & 1 deletion src/core/lowLevelFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
DefaultItemType,
} from '../types';

// To help minimization
// To help minification
const {
create: objectCreate,
assign: objectAssign,
Expand Down

0 comments on commit ba65946

Please sign in to comment.