https://github.com/sqlwwx/x-cacher
https://github.com/sqlwwx/x-cacher
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/sqlwwx/x-cacher
- Owner: sqlwwx
- Created: 2018-09-03T03:42:01.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-31T00:07:15.000Z (about 6 years ago)
- Last Synced: 2025-09-12T16:30:48.541Z (10 months ago)
- Language: JavaScript
- Homepage: https://sqlwwx.github.io/x-cacher/
- Size: 502 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# x-cacher
[](https://travis-ci.org/sqlwwx/x-cacher)
[](https://coveralls.io/github/sqlwwx/x-cacher?branch=master)
[](https://greenkeeper.io/)

[](https://codebeat.co/projects/github-com-sqlwwx-x-cacher-master)
## sample
```
import { Cacher, cacherDes } from 'x-cacher'
const cacher = new Cacher([{ type: 'memory' }])
class Person {
constructor (name) {
this.name = name
}
@cacherDes(cacher, ({ name: personName }, methodName) => personName + ':' + methodName)
async eat () {
return new Promise(resolve => {
setTimeout(() => {
resolve(this.name + ' eat: '+ Math.random())
}, 2000)
})
}
}
const personA = new Person('a')
jest.setTimeout(1000 * 60)
/* eslint-env jest */
describe('cacher', () => {
it('eat', async () => {
let startAt = Date.now()
let ret = await personA.eat()
expect(ret).toMatch(/^a eat: /)
expect(Date.now() - startAt).toBeGreaterThanOrEqual(2000)
startAt = Date.now()
let ret2 = await personA.eat()
expect(ret2).toMatch(/^a eat: /)
expect(ret).toEqual(ret2)
expect(Date.now() - startAt).toBeLessThan(1000)
})
})
```