Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MemoizeExpiring #20

Merged
merged 5 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,30 @@ These both work the same way. Subsequent calls to a memoized method without para
I generally consider it an anti-pattern for a call to a `get` accessor to trigger an expensive operation. Simply adding `Memoize()` to a `get` allows for seamless lazy-loading.

```typescript
import {Memoize} from 'typescript-memoize';
import {Memoize,MemoizeExpiring} from 'typescript-memoize';

class SimpleFoo {

// Memoize a method without parameters
@Memoize()
public getAllTheData() {
// do some expensive operation to get data
return data;
}

// Memoize a getter
@Memoize()
public get someValue() {
// do some expensive operation to calculate value
return value;
}
// Memoize a method without parameters
@Memoize()
public getAllTheData() {
// do some expensive operation to get data
return data;
}

// Memoize a method and expire the value after some time
@MemoizeExpiring(5000)
public getDataForSomeTime() {
// do some expensive operation to get data
return data;
}

// Memoize a getter
@Memoize()
public get someValue() {
// do some expensive operation to calculate value
return value;
}

}
```
Expand Down
Loading