https://github.com/express-ts/cache
A simple in-memory cache for @express.ts
https://github.com/express-ts/cache
cache di express-ts inmemory-cache typescript
Last synced: 6 months ago
JSON representation
A simple in-memory cache for @express.ts
- Host: GitHub
- URL: https://github.com/express-ts/cache
- Owner: express-ts
- License: mit
- Created: 2019-08-04T18:49:24.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-04T18:52:03.000Z (over 6 years ago)
- Last Synced: 2025-02-08T22:47:08.985Z (about 1 year ago)
- Topics: cache, di, express-ts, inmemory-cache, typescript
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @express.ts/cache
A simple in-memory cache for @express.ts
### Installation
npm install @express.ts/cache --save
### Usage
Test.ts
```typescript
import { Cache } from "@express.ts/cache";
export class Test {
protected value = Date.now();
getExecutionTime () {
return Date.now() - this.value;
}
@Cache(1000) // 1s
getExecutionTimeWithCache () {
return Date.now() - this.value;
}
}
```
App.ts
```typescript
import { Test } from "./Test";
const testInstance = new Test();
console.log([ // [ 4, 4 ]
testInstance.getExecutionTime(),
testInstance.getExecutionTimeWithCache()
]);
console.log([ // [ 24, 4 ]
testInstance.getExecutionTime(),
testInstance.getExecutionTimeWithCache()
]);
setTimeout(() => {
console.log([ // [ 1038, 1038 ]
testInstance.getExecutionTime(),
testInstance.getExecutionTimeWithCache()
]);
}, 1001)
```